Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add WSSE SOAP Header to Web Reference

I'm trying to add a WSSE SOAP Header to my service call, but most of the examples focusses on WCF. I'm not making using of WCF. I have added a Web Reference (WSDL).

I have tried various methods without success, like - overriding the GetWebRequest method:

    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
        string user = "username";
        string pwd = "password";

        System.Net.WebRequest request = base.GetWebRequest(uri);

        string auth = string.Format("Basic {0}", Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(string.Format("{0}:{1}", user, pwd))));
        request.PreAuthenticate = true;
        request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
        request.Headers.Add(HttpRequestHeader.Authorization, auth);

        return request;
    }

The WSSE Security Header should resemble something like this:

<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <UsernameToken>
            <Username>username</Username>
            <Password>password</Password>
         </UsernameToken>
      </Security>

Many thanks in advance! Kind regards,

like image 974
Richard Bailey Avatar asked Feb 14 '13 07:02

Richard Bailey


People also ask

How do you pass credentials in SOAP header?

ClientCridentials. UserName. Password = "testPass"; In this way you can pass username, password in the header to a SOAP WCF Service.

What is nonce in SOAP header?

Nonce is a randomly-generated, cryptographic token that is used to prevent replay attacks. Although nonce can be inserted anywhere in the SOAP message, it is typically inserted in the <UsernameToken> element.


1 Answers

Please refer to the following:

http://underthehood.ironworks.com/2010/01/why-doesnt-my-generated-proxy-class-build-wsse-elements-into-the-soap-request-header.html

How to add security header to a SOAP message?

Which provides the answer!

like image 175
Richard Bailey Avatar answered Oct 06 '22 23:10

Richard Bailey