C# 为什么在WCF服务中向我抛出FaultException?
让我澄清一下我的设想。我有一个使用库的WCF服务,在这个库中存在数据库模型(edmx) 在我的WCF服务中:C# 为什么在WCF服务中向我抛出FaultException?,c#,wcf,entity-framework,entity-framework-4.1,entity-framework-5,C#,Wcf,Entity Framework,Entity Framework 4.1,Entity Framework 5,让我澄清一下我的设想。我有一个使用库的WCF服务,在这个库中存在数据库模型(edmx) 在我的WCF服务中: [DataContract] public class QuestionSetInformation { [DataMember] public string Id { get; set; } [DataMember] public string SetName { get; set; } [DataMember] public strin
[DataContract]
public class QuestionSetInformation
{
[DataMember]
public string Id { get; set; }
[DataMember]
public string SetName { get; set; }
[DataMember]
public string ObjectiveName { get; set; }
}
[ServiceContract]
public interface IService1
{
[OperationContract]
QuestionSetInformation[] GetQuestionSets(string objectiveName);
}
public QuestionSetInformation[] GetQuestionSets(string objectiveName)
{
var query = from r in QuestionRepositoryManager.GetRepositories()
select new QuestionSetInformation()
{
Id = r.Id,
SetName = r.SetName,
ObjectiveName = r.ObjectiveName
};
return query.ToArray();
}
由于我的库使用了EDMX,所以我将连接字符串移动到了我的WCF,并且它使用WCF测试客户机可以完美地工作。它给了我我所期待的
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="ContosoDb" connectionString="metadata=res://*/Entities.Model1.csdl|res://*/Entities.Model1.ssdl|res://*/Entities.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=X;initial catalog=contoso2_db;persist security info=True;user id=X;password=X;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
FaultException`1是使用T4模板生成的未经处理的代码
对于数据库优先和模型优先,开发可能无法正常工作
如果在代码优先模式下使用。继续先使用数据库或模型的步骤
首先确保指定了实体框架连接字符串
在正在执行的应用程序的配置文件中。要使用这些类,
首先从数据库或模型生成,并带有代码
首先使用属性或
DBModelBuilderAPI,然后删除引发此错误的代码
例外
我在网上调查过这个错误,每个人都说使用连接字符串有问题,但我认为情况不同。我不知道如何修复它这是它使用的连接字符串的问题。。。它使用某种默认的SqlClient连接字符串(即,不是指定三个EF元数据文件的实体框架连接字符串),使它认为您是在代码优先模式下运行的
请确保连接字符串的名称相同,或者将要使用的连接字符串名称传递到DbContext构造函数中。可能会混淆此异常的来源。它来自服务器,而不是客户端。你只会在客户端看到它,但我不明白为什么只有在WCF投入生产时才会抛出这个错误
ServiceReference1.Service1Client service = new ServiceReference1.Service1Client("BasicHttpsBinding_IService1");
ServiceReference1.QuestionSetInformation[] qss = service.GetQuestionSets("something");