1

.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 の不一致により、アクション「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();
4

0 に答える 0