我在 .NET 4.0 上的 C# 中有一些简单的 WCF 客户端代码我在 Visual Studio 中进行了服务引用,并获得了如下所示的 app.config 更新:
<binding name="BasicHttpBinding_IRemoteService2" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
messageEncoding="Text">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
……一些东西……
<endpoint address="https://remote/remote.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRemoteService2"
contract="ApiRemoteService.IRemoteService"
name="BasicHttpBinding_IRemoteService2" />
这工作正常:
var client = new reportClient();
client.DoSomething();
然后我尝试在代码中严格执行相同的操作并得到一个错误:
由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action 'DoSomething' 的消息。这可能是因为合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。
这是我的代码。与我将创建不匹配的点有什么不同?
谢谢。
var basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.CloseTimeout = new TimeSpan(0,4,0);
basicHttpBinding.OpenTimeout = new TimeSpan( 0 , 4 , 0 );
basicHttpBinding.ReceiveTimeout = new TimeSpan( 0 , 4 , 0 );
basicHttpBinding.SendTimeout = new TimeSpan( 0 , 4 , 0 );
basicHttpBinding.TextEncoding = new UTF8Encoding();
basicHttpBinding.TransferMode = TransferMode.Buffered;
basicHttpBinding.MessageEncoding = WSMessageEncoding.Text;
basicHttpBinding.ReaderQuotas.MaxDepth = 32;
basicHttpBinding.ReaderQuotas.MaxStringContentLength = 8192;
basicHttpBinding.ReaderQuotas.MaxArrayLength = 16384;
basicHttpBinding.ReaderQuotas.MaxBytesPerRead = 4096;
basicHttpBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.Transport;
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
var remotey = new EndpointAddress( "https://remote/remote.svc" );
var client = new RemoteClient( basicHttpBinding , remotey );
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
client.DoSomething();