找不到WCF实体框架6 SQL提供程序

时间:2018-05-27 15:57:24

标签: entity-framework wcf exception entity-framework-6

我写了一个客户端服务器应用程序。如果服务器从EF6请求数据没有问题,也没有异常。如果客户端询问来自EF6的WFC数据,则会发现提供程序未找到异常。我的数据库是MS SQL Server 2017.CLient和Server具有相同的调试文件夹。

WFC的例外情况:

  

“找不到具有不变名称'System.Data.SqlClient'的ADO.NET提供程序的实体框架提供程序。确保提供程序已在应用程序配置文件的'entityFramework'部分中注册。请参阅http://go.microsoft.com/fwlink/?LinkId=260882了解更多信息。“

Server App.config

<?xml version="1.0" encoding="utf-8"?>

                                                 集成         安全= TRUE;数据库= PeddTax; MultipleActiveResultSets =真“/&GT;                                                                                                                              

<system.web>
    <compilation debug="true" />
</system.web>

<system.serviceModel>
    <services>
        <service name="PeddTaxServer.Communication.UserService">
            <endpoint address="http://localhost:6060/wcf/UserService" binding="basicHttpBinding"
                bindingConfiguration="" name="UserServiceEndpoint" contract="PeddTax.Communication.Interfaces.IUserService" />
        </service>
    </services>
</system.serviceModel>

客户端App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>

<system.serviceModel>
    <client>
    <endpoint address="http://localhost:6060/wcf/UserService" 
      binding="basicHttpBinding" bindingConfiguration="" 
      contract="PeddTax.Communication.Interfaces.IUserService" 
      name="UserServiceEndpoint" kind="" endpointConfiguration="" />
    </client>
</system.serviceModel>

<system.web>
    <compilation debug="true" />
</system.web>
</configuration>

WFC的IUserInterface

[ServiceContract]
public interface IUserService
{
    [OperationContract]
    void AddUser(User user);

    [OperationContract]
    void UpdateUser(User user);

    [OperationContract]
    User GetUser(Guid id);

    [OperationContract]
    List<User> GetUsers();

    [OperationContract]
    void DeleteUser(User user);
}

WFC的UserService

    public class UserService : IUserService, IService
{
    UserRepository userRep = new UserRepository();

    public void AddUser(User user)
    {
        userRep.Add(user);
        userRep.Save();
    }

    public void DeleteUser(User user)
    {
        userRep.Delete(user);
        userRep.Save();
    }

    public User GetUser(Guid id)
    {
        return userRep.GetSingle(id);
    }

    public List<User> GetUsers()
    {
        return userRep.GetAll().ToList();
    }

    public void UpdateUser(User user)
    {
        userRep.Edit(user);
        userRep.Save();
    }
}

在userRepository中有这个方法

public IQueryable<T> GetAll()
{
    IQueryable<T> query = entities.Set<T>();
    return query;
}

1 个答案:

答案 0 :(得分:0)

如果你想看到它被抛出的地方,请在Visual Studio中

1)Turn on all exceptions

2)在正确的项目as suggested here

上重新安装EF