自定义SOAP标头

本文关键字:标头 SOAP 自定义 | 更新日期: 2023-09-27 18:23:54

我正在尝试将Java Web服务客户端转换为C#。我添加了一个自定义SoapHeader类来生成身份验证所需的标头,但它们的格式不正确。我是C#Web服务的新手,所以非常感谢您的帮助。

这是我需要标题的格式:

  <soapenv:Header>  
     <USER soapenv:mustUnderstand="0" xsi:type="xsd:string">xxx</USER>  
     <PASSWORD soapenv:mustUnderstand="0" xsi:type="xsd:string">yyy</PASSWORD> 
  </soapenv:Header> 

以下是C#客户端生成的内容:

  <soap:Header>
     <wsa:Action></wsa:Action>
     <wsa:MessageID>urn:uuid:ecb804bb-1104-4bfc-a8f8-c5f757d428fb</wsa:MessageID>
     <wsa:ReplyTo>
        <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
     </wsa:ReplyTo>
     <wsa:To>http://localhost:8081/emsapi/services/PSXAPI/r09_00_00</wsa:To>
     <wsse:Security>
        <wsu:Timestamp wsu:Id="Timestamp-4e8c838e-230c-4fb3-99b0-74f46f3652fa">
           <wsu:Created>2013-07-19T17:26:55Z</wsu:Created>
           <wsu:Expires>2013-07-19T17:31:55Z</wsu:Expires>
        </wsu:Timestamp>
     </wsse:Security>
  </soap:Header>

我需要在SoapHeader类中放入什么才能正确格式化它们?供您参考,这里是标题类:

public class AuthHeaders : SoapHeader {
    [System.Xml.Serialization.SoapElement("USER")]
    [System.Xml.Serialization.SoapAttribute("USER")]
    public string USER;
    [System.Xml.Serialization.SoapElement("PASSWORD")]
    public string PASSWORD;
}

自定义SOAP标头

SoapExtension类提供了最终解决方案,并根据需要修改了属性。