WCF/C# クライアントを使用して SOAP Web サービスを利用しようとしています。
サーバーの wsdl は、wsdl ファイルで次のようにセキュリティ ポリシーを定義します。
<wsp:Policy wsu:Id="BindingSecPolicy">
<wsp:ExactlyOne>
<wsp:All>
<sp:AsymmetricBinding>
...
このポリシーはバインディング定義で参照されます。
現在、このサービスと通信できる WCF でクライアントをセットアップしようとしています。新しい .NET 4.5 コンソール アプリケーションを作成し、サービス リファレンスを追加し、ビジュアル スタジオでサービスのクラスを自動生成しました。
これが、サービスを呼び出そうとする方法です。
WSDualHttpBinding binding = new WSDualHttpBinding();
binding.Security.Mode = WSDualHttpSecurityMode.None;
binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
binding.Security.Message.NegotiateServiceCredential = false;
binding.ClientBaseAddress = new Uri("http://localhost:5555");
EndpointAddress address = new EndpointAddress("http://localhost:9080/CustomerServicePort");
CustomerServiceClient client = new CustomerServiceClient(binding, address);
foreach (customer c in client.getCustomersByName("foo")) {
Console.WriteLine(c);
}
client.Close();
Console.ReadKey();
デュアル バインディングを使用する理由は、wsdl が WS-RM も要件として定義しているためです。現時点では証明書を指定していないことを認識しているため、このセットアップは実際には機能しません。このコードを実行すると、ポリシーがサポートされていないという例外が発生します。
Warning 1 Custom tool warning: Cannot import wsdl:binding
Detail: An exception was thrown in a call to a policy import extension.
Extension: System.ServiceModel.Channels.SecurityBindingElementImporter
Error: An unsupported security policy assertion was detected during the security policy import: <sp:AsymmetricBinding xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702">
<wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy">
<sp:InitiatorToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:RequireThumbprintReference />
<sp:WssX509V3Token10 />
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:InitiatorToken>
<sp:RecipientToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/I...
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://customerservice.example.com']/wsdl:binding[@name='CustomerServiceServiceSoapBinding'] C:\projects\cxf-samples\wsrm-client-csharp\ConsoleApplication1\ConsoleApplication1\Service References\CustomerService\Reference.svcmap 1 1 b2bclientcsharp
これは、証明書などを提供しているかどうかを実際に確認する前に発生しているため、まだ設定していません。Microsoft のドキュメントによると、WS-SecurityPolicy 1.2 がサポートされており、サービスが定義しているポリシーと非常によく似たポリシーの例も示されています。
http://msdn.microsoft.com/en-us/library/aa738565.aspxを参照して、「Using X.509 Certificates for Service Authentication」を検索してください。
ここで私が間違っている一般的なアイデアはありますか?
乾杯、アンディ