在EndpointDispatcher上具有ContractFilter不匹配的WCF客户端

时间:2012-09-10 20:16:08

标签: wcf wcf-binding

我在.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();

然后我尝试在代码中严格执行相同的操作并收到错误:

  

无法处理带有Action'DoSomething'的消息   接收器,由于EndpointDispatcher上的ContractFilter不匹配。   这可能是因为合同不匹配(行动不匹配)   发送者和接收者之间)或绑定/安全性不匹配   发件人和收件人。检查发件人和收件人是否有   相同的合同和相同的约束(包括安全要求,   例如消息,传输,无)。

这是我的代码。与创造不匹配的地方有什么不同?

感谢。

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();

0 个答案:

没有答案