私のデスクトップ アプリケーション (C#、WPF、WCF、.NET4.0) では、サービス参照を追加します。
これは、Soap Envelope Header で証明書と UserNameToken を使用する Web サービス (SOAP) です。
この Web サービスの WSDL を使用して、サービス参照 (ソリューション -> サービス参照 -> サービス参照の追加) を追加します。私のapp.configには次のものがあります:
<customBinding>
<binding name="tmsIntegrationServiceSOAP">
<!-- WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'urn:CDM/tmsIntegrationService/': -->
<!-- <wsdl:binding name='tmsIntegrationServiceSOAP'> -->
<!-- <sp:SupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">..</sp:SupportingTokens> -->
<mtomMessageEncoding messageVersion="Soap11" />
<httpsTransport />
</binding>
</customBinding>
<endpoint address="https://XXX/CDM/tmsIntegrationService"
binding="customBinding" bindingConfiguration="tmsIntegrationServiceSOAP"
contract="RABEN.GS1.tmsIntegrationService" name="tmsIntegrationServiceSOAP" />
次のようにユーザー名とパスワードを渡します。
var ssc = new GS1.tmsIntegrationServiceClient();
ssc.ClientCredentials.UserName.UserName = "test";
ssc.ClientCredentials.UserName.Password = "testPassword";
ssc.Endpoint.Behaviors.Add(new InspectorBehavior());
リクエスト XML を (メッセージ インスペクタを使用して) 取得すると、soap ヘッダーに UserNameToken がないことがわかります
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:CDM/tmsIntegrationService/importTransportInstruction</Action>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPoy3hcoBMqQ5Kme7yqEiHKs0AAAAAyxy+QnWD8U60kqJZWaGfvYD8RN14nUVIjC0RuEyVBa8ACQAA</VsDebuggerCausalityData>
</s:Header>
<s:Body ...
私はbasicHttpBindingを使用しようとしています:
<binding name="secured">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
<endpoint address="https://XXX/CDM/tmsIntegrationService"
binding="basicHttpBinding" bindingConfiguration="secured" contract="RABEN.GS1.tmsIntegrationService"
name="tmsIntegrationServiceSOAP" />
結果を終了します。
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:CDM/tmsIntegrationService/importTransportInstruction</Action>
</s:Header>
wsHttpBinding を使用しようとすると:
<wsHttpBinding>
<binding name="RabenBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
<endpoint address="https://XXX/CDM/tmsIntegrationService"
binding="wsHttpBinding" bindingConfiguration="RabenBinding"
contract="RABEN.GS1.tmsIntegrationService" name="tmsIntegrationServiceSOAP" />
結果:
<s:Header>
<a:Action s:mustUnderstand="1">urn:CDM/tmsIntegrationService/importTransportInstruction</a:Action>
<a:MessageID>urn:uuid:701a0fff-c4aa-4f37-a299-ec6d272e51e7</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
誰かが私が間違っていることを教えてもらえますか?
EDIT - 2017-06-21 20:00 証明書がローカル マシンにインストールされている
<behaviors>
<endpointBehaviors>
<behavior name="RabenBehavior">
<clientCredentials>
<clientCertificate findValue="this is footprint of certificate"
storeLocation="CurrentUser" storeName="My" x509FindType="FindByThumbprint" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
この動作をエンドポイントに追加しています:
<endpoint address="https://XXX/CDM/tmsIntegrationService"
behaviorConfiguration="RabenBehavior" binding="wsHttpBinding"
bindingConfiguration="RabenBinding" contract="RABEN.GS1.tmsIntegrationService"
name="tmsIntegrationServiceSOAP" />
EDIT 2017-06-21 20:58 使用しようとしています <mtomMessageEncoding messageVersion="Soap11" />
<binding name="myCustomBindingConfig">
<security defaultAlgorithmSuite="Default"
authenticationMode="UserNameOverTransport"
requireDerivedKeys="true"
includeTimestamp="false" messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
<mtomMessageEncoding messageVersion="Soap11" />
<httpsTransport maxReceivedMessageSize="2000000000" />
</binding>
ただし、ヘッダーにはまだユーザー名トークンが含まれていません
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:CDM/tmsIntegrationService/importTransportInstruction</Action>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo0OlG2DVOLdKniJmYU2kvwUAAAAAujMM+x53aEWJYYd4GKyk+PlCKXIih9xLrE0V5TayKhQACQAA</VsDebuggerCausalityData>
</s:Header>
EDIT 2017-06-21 21:36 <textMessageEncoding messageVersion="Soap11" />
VSによるカスタムバインディング生成で使用してみてください
<binding name="tmsIntegrationServiceSOAP">
<!-- WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'urn:CDM/tmsIntegrationService/': -->
<!-- <wsdl:binding name='tmsIntegrationServiceSOAP'> -->
<!-- <sp:SupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">..</sp:SupportingTokens> -->
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport />
</binding>
しかし、それは何の効果ももたらしません - 要求 XML にユーザー名トークンがありません:
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:CDM/tmsIntegrationService/importTransportInstruction</Action>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo0wJNixU4QRBhGEUAC3pw50AAAAA/fPJ+e50KUSGbYXwcmoGwgqymCvLXJZIhKg/nKdV97cACQAA</VsDebuggerCausalityData>
</s:Header>