WCF服务客户端;服务器没有提供有意义的答复";例外

本文关键字:quot 有意义 例外 客户端 服务 服务器 WCF | 更新日期: 2023-09-27 18:20:55

我有一个承载WCF服务的Windows服务。我还有一个连接到它的客户端,消息会来回发送。当我从客户端向服务发送消息时,客户端会捕获以下异常:

服务器没有提供有意义的答复;这可能是由于合约不匹配、会话提前关闭或内部服务器错误造成的。

这有点奇怪,因为我不希望服务直接回复客户端发送的消息。服务成功地获得了消息,但随后客户端抛出了此异常,并且似乎失去了与服务的连接。

这是Service app.config。忽略关于RESTfull服务的部分:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="OSAERest.api" behaviorConfiguration="MyServiceBehavior">
        <endpoint address="http://localhost:8732/api"
                  binding="webHttpBinding"
                  contract="OSAERest.IRestService"
                  behaviorConfiguration="WebHttp"/>
      </service>
      <service name="WCF.WCFService" behaviorConfiguration="WCFBehavior">
        <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="WCFBinding" contract="WCF.IWCFService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint
          address="mex"
          binding="mexHttpBinding"
          bindingConfiguration=""
          contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="WCFBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceTimeouts transactionTimeout="05:05:00" />
          <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500"
           maxConcurrentInstances="2147483647" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="WebHttp">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WCFBinding">
          <security mode="None">
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
</configuration>

这是客户端app.config:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="ServiceIP" value="127.0.0.1"/>

  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="WSDualHttpBinding_IWCFService" closeTimeout="00:01:00"
          clientBaseAddress="http://localhost:8733/Design_Time_Addresses/WCF/WCFService/"
          openTimeout="00:00:10" receiveTimeout="00:10:00" sendTimeout="00:00:10"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" />
          <security mode="None">
            <message clientCredentialType="Windows" negotiateServiceCredential="true" />
          </security>
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/"
        binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IWCFService"
        contract="WCFService.IWCFService" name="WSDualHttpBinding_IWCFService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

为什么客户端会捕获此异常?

编辑:

如果有帮助的话,这是我向服务发送消息的C#代码:

WCFServiceClient wcfObj;
EndpointAddress ep = new EndpointAddress("http://localhost:8731/Design_Time_Addresses/WCF/WCFService/");
InstanceContext context = new InstanceContext(this);
wcfObj = new Manager_WPF.WCFService.WCFServiceClient(context, "WSDualHttpBinding_IWCFService", ep);
wcfObj.Subscribe();
wcfObj.messageHost(message);

WCF服务客户端;服务器没有提供有意义的答复";例外

我在silverlight客户端和双工tcp绑定方面也遇到过同样的问题。该问题是由在从wcf方法调用返回之前调用客户端的回调引起的。我已经通过将回调调用放入后台线程修复了这个问题:

...
ThreadPool.QueueUserWorkItem(state =>
{                   
    //this notifies service subscribers (calls registered callbacks)                               
    OnConfigurationUpdated(EventArgs.Empty); 
});
return;