I need to send a createShipmentRequest() to DHLWebSerivces and my problem is to add a security header to the soap request.
Edited to add the DHL documentation:
I'm trying the last solution proposed here How To Pass Soap Header When WSDL Doesn't Define It?.
public partial class SecurityHeader : SoapHeader
{
public string Username { get; set; }
public string Password { get; set; }
}
public partial class gblExpressRateBook
{
public SecurityHeader securityHeader = new SecurityHeader() {
EncodedMustUnderstand = "1", Username = "*****", Password = "*****" };
protected override XmlWriter GetWriterForMessage(SoapClientMessage message,
int bufferSize)
{
message.Headers.Add(securityHeader);
return base.GetWriterForMessage(message, bufferSize);
}
}
Here is the result in Fiddler:
Edited to add the entire first line "soap:Envelope".
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
SecurityHeader [ xmlns=http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/ShipmentMsgRequest ]
...
And here is what I should have according to a code sample of DHL:
Edited to add the indentation of the code.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:glob="http://scxgxtt.phx-dc.dhl.com/glDHLExpressLabel/providers/globalLabel">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-5" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>*****</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*****</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">*****************</wsse:Nonce>
<wsu:Created>2010-02-12T17:40:39.124Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
Edited to add SOAPUI request done via Fiddler:
Sent request via Fiddler:
Received response via Fiddler:
Can someone please help me build this "wsse:Security" header?