從C#程序中,我試圖調用用Java編寫的WebService。 如果我使用SOAPUI調用WS我可以小提琴手看到,調用如下:從C調用Java WS#
<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.
那麼怎麼辦我使用用戶名和密碼添加肥皂標題以在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' 未被此郵件的收件人理解,導致郵件未被處理。
此錯誤通常表示此消息的發件人已啓用接收方無法處理的通信協議。 請確保客戶端綁定的配置與服務的綁定一致。
您是否考慮過爲WS購買認證,以便您可以切換到https?那不超過20美元/年.. – Marc
我無法控制WS,並且發佈者告訴我WS上沒有證書或其他安全性(部分用於用戶名和SOAP標頭中的PW) –