【发布时间】:2016-11-18 07:46:39
【问题描述】:
我试图从一个 C# 程序调用一个用 Java 编写的 WebService。 如果我使用 SoapUi 调用 WS,我可以在 fiddler 中看到调用如下所示:
<soap:Envelope xmlns:ser="http://service.webservice.com" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-8684DEB94ABXXXXXXXXXX362973">
<wsse:Username>MyUserName</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MyPassword</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">fjwe5h78k7vgheedRv21g==</wsse:Nonce>
<wsu:Created>2016-11-17T11:53:56.297Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<ser:getTrades>
<ser:filter>
<ser:fromValueDate>2015-03-23</ser:fromValueDate>
<ser:toValueDate>2015-03-23</ser:toValueDate>
</ser:filter>
</ser:getTrades>
</soap:Body>
</soap:Envelope>
问题是 VisualStudio 创建的类没有标题选项
// CODEGEN: The optional WSDL extension element 'Policy' from namespace
'http://schemas.xmlsoap.org/ws/2004/09/policy' was not handled.
那么如何添加带有用户名和密码的 Soap 标头以在 C# 中进行调用?
我也一直在寻找使用 WCF,以及来自 wsdl(这里是部分)
.
.
.
<wsdl:binding name="TradeRetrieverServiceSOAP12Binding" type="ns0:TradeRetrieverServicePortType">
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" Id="UsernameTokenOverHTTPS">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false"/>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Lax/>
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"/>
</wsp:Policy>
</sp:SignedSupportingTokens>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
.
.
它创建这个绑定:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="TradeRetrieverServiceSOAP12Binding">
<security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport"
requireDerivedKeys="true" securityHeaderLayout="Lax" includeTimestamp="false">
<localClientSettings detectReplays="false" />
<localServiceSettings detectReplays="false" />
</security>
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://Myservices/TradeRetrieverService"
binding="customBinding" bindingConfiguration="TradeRetrieverServiceSOAP12Binding"
contract="ServiceReference1.TradeRetrieverServicePortType" name="TradeRetrieverServiceSOAP12port_http" />
</client>
</system.serviceModel>
但这给了我这个错误:
The provided URI scheme 'http' is invalid; expected 'https'.
Parameter name: via
网址是http而不是https
所以我在这里有货。有什么想法吗?
编辑
我现在得到数据,在提琴手中,在代码中我得到这个错误:
来自命名空间“http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd”的标头“Security”
此邮件的收件人不理解,导致邮件无法处理。
此错误通常表明此消息的发送方启用了接收方无法处理的通信协议。
请确保客户端绑定的配置与服务的绑定一致。
【问题讨论】:
-
您是否考虑过为 WS 购买证书以便切换到 https?那不超过20美元/年..
-
我无法控制 WS,开发人员告诉我 WS 上没有证书或其他安全性(soap header 中的用户名和 PW 部分)
标签: c# web-services wcf soap