我想在调用Web服务之前在c#中添加自定义soap头信息.我正在使用SOAP Header类来完成这项工作.我可以部分地这样做但不完全按我需要的方式完成.这是我需要肥皂头看起来像
<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>
...
Run Code Online (Sandbox Code Playgroud)
我可以添加soap header如下
<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>
Run Code Online (Sandbox Code Playgroud)
我无法做的是添加包含"UsernameToken"的"Security"元素,如第一个示例中所示.任何帮助,将不胜感激.