我有一个客户端控制台应用程序与WCF服务对话,我得到了以下错误:“服务器没有提供有意义的回复;这可能是由于约定不匹配、过早关闭会话或内部服务器错误造成的。”
我想这是因为合同不匹配,但我不知道为什么。服务本身运行得很好,在我添加模拟代码之前,这两个部分一直在一起工作。
有人能看出哪里出了问题吗?
下面是客户端,全部都是用代码完成的:
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
EndpointAddress endPoint = new EndpointAddress(new Uri("net.tcp://serverName:9990/TestService1"));
ChannelFactory<IService1> channel = new ChannelFactory<IService1>(binding, endPoint);
channel.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
IService1 service = channel.CreateChannel();
下面是WCF服务的配置文件:
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="MyBinding">
<security mode="Message">
<transport clientCredentialType="Windows"/>
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WCFTest.ConsoleHost2.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization impersonateCallerForAllOperations="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WCFTest.ConsoleHost2.Service1Behavior"
name="WCFTest.ConsoleHost2.Service1">
<endpoint address="" binding="wsHttpBinding" contract="WCFTest.ConsoleHost2.IService1">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint binding="netTcpBinding" bindingConfiguration="MyBinding"
contract="WCFTest.ConsoleHost2.IService1" />
<host>
<baseAddresses>
<add baseAddress="http://serverName:9999/TestService1/" />
<add baseAddress="net.tcp://serverName:9990/TestService1/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
发布于 2010-04-02 22:32:08
对我来说,抛出这个错误消息是因为我的web.config服务行为在默认情况下有一个低的消息限制,所以当WCF返回比方说200000字节,而我的限制是64000字节时,响应被截断,因此你得到了"...没有意义的回复“。它是有意义的,它只是被截断了,无法解析。
我将粘贴修复此问题的web.config更改:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="YourNameSpace.DataServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceTimeouts transactionTimeout="05:05:00" />
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500"
maxConcurrentInstances="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
maxItemsInObjectGraph值是最重要的!
我希望这对任何人都有帮助。
发布于 2016-02-23 19:51:43
我也遇到了类似的问题。在花了2个小时在这个问题上绞尽脑汁并试图在网上找到答案后,我决定使用System.Runtime.Serialization.DataContractSerializer在服务器端序列化和反序列化返回值/对象,最终发现我错过了在其中一个枚举上添加EnumMember属性。
您可能正面临着类似的问题。
下面是帮助我解决这个问题的代码片段:
var dataContractSerializer = new System.Runtime.Serialization.DataContractSerializer(typeof(MyObject));
byte[] serializedBytes;
using (System.IO.MemoryStream mem1 = new System.IO.MemoryStream())
{
dataContractSerializer.WriteObject(mem1, results);
serializedBytes = mem1.ToArray();
}
MyObject deserializedResult;
using (System.IO.MemoryStream mem2 = new System.IO.MemoryStream(serializedBytes))
{
deserializedResult = (MyObject)dataContractSerializer.ReadObject(mem2);
}
发布于 2009-08-12 06:26:22
好了,我刚刚更改了客户端,使其使用配置文件而不是代码,并且我得到了相同的错误!
代码:
ServiceReference1.Service1Client client = new WCFTest.ConsoleClient.ServiceReference1.Service1Client("NetTcpBinding_IService1");
client.PrintMessage("Hello!");
这是客户端的配置文件,是从服务中新生成的...这让我觉得这可能不是合同不匹配的错误
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://servername:9999/TestService1/" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
name="WSHttpBinding_IService1">
<identity>
<dns value="
 " />
</identity>
</endpoint>
<endpoint address="net.tcp://serverName:9990/TestService1/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
name="NetTcpBinding_IService1">
<identity>
<userPrincipalName value="MyUserPrincipalName " />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
https://stackoverflow.com/questions/1264431
复制相似问题