8
我想在調用Web服務之前在C#中添加自定義SOAP頭信息。我正在使用SOAP Header類來完成此操作。我可以做到這一點,但不完全是我需要的方式。這裏是我所需要的肥皂頭看起來像在C#中爲Web服務調用添加自定義SOAPHeader
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken>
<Username>USERID</Username>
<Password>PASSWORD</Password>
</UsernameToken>
</Security>
</soap:Header>
<soap:Body>
...
我能夠添加SOAP頭,如下
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<UsernameToken xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<Username>UserID</Username>
<Password>Test</Password>
</UsernameToken>
</soap:Header>
<soap:Body>
我什麼不能夠做的就是添加它包裝的「安全性」元素如第一個示例中的「UsernameToken」。任何幫助,將不勝感激。
提供的示例代碼的任何機會呢?提前致謝。 (我正在查看鏈接/步驟,並試圖使他的問題與他/ Dudgeon的示例代碼一致,但不直接對應/點擊我如何翻譯安全頭部要求)。 – Terry
參見上面我添加了一些示例代碼。順便說一句,希望這有助於 –
- 這不是一個WCF服務,可能對某些人來說很明顯 –