Search code examples
c#soapwsdl

Custom SOAP Headers


I am trying to convert a Java Web Service client to C#. I have add a custom SoapHeader class to generate the necessary headers for authentication, but they are not being correctly formatted. I am very new to C# Web Services, so any help is very appreciated.

Here is the format in which i need the headers:

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

Here is what is being generated by the C# client:

  <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>

What do i need to put into my SoapHeader class to format them correctly? For your reference, here is the header class:

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;
}

Solution

  • Final solution came with the SoapExtension class and modifying the attributes as necessary.