我有一个托管WCF服务的Windows服务。我还有一个连接到它的客户端,来回发送消息。当我从客户端向服务发送消息时,客户端会捕获以下内容:
服务器未提供有意义的回复;这可能是由于合同不匹配,过早的会话关闭或内部服务器错误造成的。
这有点奇怪,因为我不希望服务直接回复客户端发送的消息。该服务成功获取消息,但随后客户端抛出此异常并且似乎失去与服务的连接。
这是服务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);
答案 0 :(得分:1)
我遇到了与silverlight客户端和双工tcp绑定相同的问题。 probem是在从wcf方法调用返回之前调用回调客户端引起的。我通过将回调调用放入后台线程来解决这个问题:
...
ThreadPool.QueueUserWorkItem(state =>
{
//this notifies service subscribers (calls registered callbacks)
OnConfigurationUpdated(EventArgs.Empty);
});
return;