在我的桌面應用程序(C#,WPF,WCF,.NET4.0)中,我添加了一個服務引用。C#WCF服務參考 - 無法創建UserNameToken
這是在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>
能有人告訴我,我做錯了什麼?
編輯 - 2017年6月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>
我在端點安裝此behavion上:
<endpoint address="https://XXX/CDM/tmsIntegrationService"
behaviorConfiguration="RabenBehavior" binding="wsHttpBinding"
bindingConfiguration="RabenBinding" contract="RABEN.GS1.tmsIntegrationService"
name="tmsIntegrationServiceSOAP" />
編輯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>
但是頭還是不containt用戶名令牌
<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年6月21日21:36 嘗試通過VS
使用<textMessageEncoding messageVersion="Soap11" />
在自定義綁定generatet
<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>
您是否嘗試過使用在你的自定義綁定中使用'而不是''? –
bnem
我試試這個(編輯編輯2017-06-21 20:58) – pejoter
你的編輯仍然包含mtomMessageEncoding – bnem