0

我正在尝试将 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;
}
4

1 回答 1

0

最终解决方案附带 SoapExtension 类并根据需要修改属性。

于 2013-07-19T19:02:22.523 回答