WCF クライアントからサード パーティの WSE 3.0 Web サービスに接続できません。この KB 記事に示されているように、カスタム バインディング クラスを実装しました。
http://msdn.microsoft.com/en-us/library/ms734745.aspx
この問題は、Web サービスで使用されるセキュリティ アサーション (UsernameOverTransport) に関係しているようです。
メソッドを呼び出そうとすると、次の例外が発生します。
System.InvalidOperationException: 'MyWebServiceSoap'.'[namespace]' コントラクトの 'WseHttpBinding'.'[namespace]' バインディングは、トランスポート レベルの整合性と機密性を必要とする認証モードで構成されています。ただし、トランスポートは完全性と機密性を提供できません。
ユーザー名、パスワード、および CN 番号が必要です。ベンダーから提供されたサンプル コードでは、これらの資格情報が Microsoft.Web.Services3.Security.Tokens.UsernameToken にバンドルされています。ベンダーから提供された例を次に示します。
MyWebServiceWse proxy = new MyWebServiceWse();
UsernameToken token = new UsernameToken("Username", "password", PasswordOption.SendPlainText);
token.Id = "<supplied CN Number>";
proxy.SetClientCredential(token);
proxy.SetPolicy(new Policy(new UsernameOverTransportAssertion(), new RequireActionHeaderAssertion()));
MyObject mo = proxy.MyMethod();
これは、WSE 3.0 がインストールされた 2.0 アプリから正常に動作します。これは、私の WCF クライアントからのコードのスニペットです。
EndpointAddress address = new EndpointAddress(new Uri("<web service uri here>"));
WseHttpBinding binding = new WseHttpBinding(); // This is the custom binding I created per the MS KB article
binding.SecurityAssertion = WseSecurityAssertion.UsernameOverTransport;
binding.EstablishSecurityContext = false;
// Not sure about the value of either of these next two
binding.RequireDerivedKeys = true;
binding.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
MembershipServiceSoapClient proxy = new MembershipServiceSoapClient(binding, address);
// This is where I believe the problem lies – I can’t seem to properly setup the security credentials the web service is expecting
proxy.ClientCredentials.UserName.UserName = "username";
proxy.ClientCredentials.UserName.Password = "pwd";
// How do I supply the CN number?
MyObject mo = proxy.MyMethod(); // this throws the exception
この質問に対する答えを探して、Web を精査しました。いくつかの情報源 (MS KB 記事など) は私を近づけますが、私はこぶを乗り越えることができないようです. 誰かが私を助けることができますか?