我有一个客户端控制台应用程序与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>
https://stackoverflow.com/questions/1264431
复制相似问题