如何摆脱WCF测试客户端错误?

时间:2016-09-11 07:56:49

标签: wcf

我有WCF服务,它在使用开发主机时可以在WCF测试客户端中使用。但是,当我使用IIS 7并尝试运行某些方法时,会出现错误:

The underlying provider failed on Open.

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IDatabaseService.GetAllUsersWithRoles()
   at DatabaseServiceClient.GetAllUsersWithRoles()

该服务通过Entity Framework与MS SQL Server进行通信。 IIS 7和MS SQL Server放在同一台计算机上。

如何让它发挥作用?

更新 - 这是web.config文件的内容:

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation targetFramework="4.0" debug="true">
            <assemblies>
                <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            </assemblies>
        </compilation>
    </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    <connectionStrings>
        <add name="ForisTestLogsEntities" connectionString="metadata=res://*/ForisTestLogsModel.csdl|res://*/ForisTestLogsModel.ssdl|res://*/ForisTestLogsModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=GORAN-PC\SQLEXPRESS;Initial Catalog=ForisTestLogs;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
    </connectionStrings>
</configuration>

1 个答案:

答案 0 :(得分:0)

您的配置文件未定义任何服务或端点。请查看MSDN上的以下页面,其中说明了如何执行此操作:Configuring Services

您必须在Web.config文件中添加<services><bindings>元素。

作为替代方案,您可以尝试在.NET framework 4.0中引入的简化配置:Simplified Configuration

如果您不想手动编辑Web.config文件,请尝试使用配置编辑器工具。只需右键单击Web.config文件,然后从上下文菜单中选择“编辑WCF配置”。有关该工具的更多信息,请访问here