简体   繁体   中英

Why does throws me a FaultException in WCF Service?

Let me clarify my scenario. I've got a WCF Service where uses a library, in this library exist the database model (edmx).

In my WCF Service:

[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();
}

As my library uses the EDMX, so I moved the connection strings to my WCF and it works PERFECTLY using the WCF Test Client. It delivers me what I'm expecting.

<?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=&quot;data source=X;initial catalog=contoso2_db;persist security info=True;user id=X;password=X;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>

But at a time using this WCF in a desktop application, I've got the following exception:

        ServiceReference1.Service1Client service = new ServiceReference1.Service1Client("BasicHttpsBinding_IService1");
        ServiceReference1.QuestionSetInformation[] qss = service.GetQuestionSets("something");

FaultException`1 was unhandled Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.

I have investigated this error in the web, everyone tells about a problem using the connection string but I supposed it's not the same case. I don't have idea about how to fix it

This is a problem with the connection string it's using... It's using some sort of default SqlClient connection string (ie not an entity framework connections string that specifies the three EF metadata files) making it think you're running in Code First mode.

Be sure that your connection string is named the same or that you pass the connection string name you want to use into your DbContext constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM