Modify SOAP Envelope or Header with namespace RRS feed

  • Question

  • Hey Folks,

    I know this question has been asked before, but the answers either make no sense to me or are way too complex.

    I need to generate a soap message like below.  Note that I'm working in WCF 4.5 and need to consume a Java web service that I have no control over.  I'm working in the client only.

    soap:Envelope xmlns:soap="" xmlns:cor="">
          <wsse:Security soap:mustUnderstand="true" xmlns:wsse="">
             <wsse:UsernameToken wsu:Id="UsernameToken-15846359" xmlns:wsu="">
                <wsse:Password Type="</soap:Envelope>

    Don't worry about the SOAP body here, that part works.  Note that the namespace wsse is defined in the Security tag.

    As far as I can tell, there is no way to assign a prefix to an xmlns in the CreateHeader method in the Message Inspector.  In other words, the code below generates xmlns=".....", NOT xmlns:wsse=".....".  Therefore, wsse is undefined when trying to send the request.

    string headerText = "<wsse:UsernameToken xmlns:wsu=\"\" wsu:Id=\"UsernameToken-15846359\">" +
                "<wsse:Username>{0}</wsse:Username>" +
                "<wsse:Password Type=\"\">{1}</wsse:Password>" +
    headerText = string.Format(headerText, "username", "password");
    MessageHeader myHeader = MessageHeader.CreateHeader("wsse:Security", "", headerText, true);

    This generates the following request:

    <s:Envelope xmlns:s="">
    		<Action a:mustUnderstand="1" xmlns="" xmlns:a="">RealTimeTransaction</Action>
    		<VsDebuggerCausalityData xmlns="">uIDPo+xMbEtrZ6dPiGlQ6t2DEO4BAAAAXaRLp2XGvUqS7yfpmzdK9wDLv8Nbp79CgET6obHZa3EACQAA</VsDebuggerCausalityData>
    		<wsse:Security s:mustUnderstand="1" xmlns="">
    			<wsse:UsernameToken xmlns:wsu="" wsu:Id="UsernameToken-15846359">
    				<wsse:Password Type="">password</wsse:Password>
    Obviously, wsse is undefined.  It would work if I could add xmlns:wsse="....." to the Envelope tag, but I can't find any way to do this.

    One "solution" I found just says: "can you pass the client code wich creates a message and calls the service?"

    What the heck does that mean??

    Other solutions suggest creating a custom encoder.  From what I've seen of that it's way over my head, way too complex, and probably wouldn't work anyway since I have no access to the service code and multitudes of other limitations.

    There has GOT to be a simple way to resolve this!



    Friday, January 10, 2014 3:01 PM


  • Hello Larry,

    I know your pain as I have had other integration issues when calling a java service from WCF.  Something to keep in mind is not all java services are the same so it does depend on the service; and unfortunately when the service owners are not available to answer questions, it could end up being trial and error to get this to work.

    If the java service is parsing standard xml then the significance of wsse is not important.  For example:

    <wsse:Security soap:mustUnderstand="true" xmlns:wsse="">
        <wsse:UsernameToken wsu:Id="UsernameToken-15846359" xmlns:wsu="">
            <wsse:Password Type="

    is equivalent to

    <ns:Security soap:mustUnderstand="true" xmlns:ns="">
        <ns:UsernameToken wsu:Id="UsernameToken-15846359" xmlns:wsu="">
            <ns:Password Type="

    So, you might be get luck if you change your create header to:

    string headerText = "<UsernameToken xmlns:wsu=\"\" wsu:Id=\"UsernameToken-15846359\">" +
                "<Username>{0}</Username>" +
                "<Password Type=\"\">{1}</Password>" +
    headerText = string.Format(headerText, "username", "password");
    MessageHeader myHeader = MessageHeader.CreateHeader("Security", "", headerText, true);

    Because you are then saying the UsernameToken element and its children are of the "" namespace.


    Monday, January 13, 2014 3:06 AM