none
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="http://www.w3.org/2003/05/soap-envelope" xmlns:cor="http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd">
       <soap:Header>
          <wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
             <wsse:UsernameToken wsu:Id="UsernameToken-15846359" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                <wsse:Username>username</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1</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=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"UsernameToken-15846359\">" +
                "<wsse:Username>{0}</wsse:Username>" +
                "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">{1}</wsse:Password>" +
                "</wsse:UsernameToken>";
    headerText = string.Format(headerText, "username", "password");
    MessageHeader myHeader = MessageHeader.CreateHeader("wsse:Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", headerText, true);
                
    request.Headers.Add(myHeader);

    This generates the following request:

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    	<s:Header>
    		<Action a:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" xmlns:a="http://schemas.xmlsoap.org/soap/envelope/">RealTimeTransaction</Action>
    		<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo+xMbEtrZ6dPiGlQ6t2DEO4BAAAAXaRLp2XGvUqS7yfpmzdK9wDLv8Nbp79CgET6obHZa3EACQAA</VsDebuggerCausalityData>
    		<wsse:Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    			<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-15846359">
    				<wsse:Username>username</wsse:Username>
    				<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
    			</wsse:UsernameToken>
    		</wsse:Security>
    	</s:Header>
    </s:Envelope>
    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!

    Thanks!!!

    Larry

    Friday, January 10, 2014 3:01 PM

Answers

  • 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="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-15846359" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>username</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1
    	</wsse:UsernameToken>
    </wsse:Security>

    is equivalent to

    <ns:Security soap:mustUnderstand="true" xmlns:ns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <ns:UsernameToken wsu:Id="UsernameToken-15846359" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <ns:Username>username</ns:Username>
            <ns:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1
    	</ns:UsernameToken>
    </ns:Security>

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

    string headerText = "<UsernameToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"UsernameToken-15846359\">" +
                "<Username>{0}</Username>" +
                "<Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">{1}</Password>" +
                "</UsernameToken>";
    headerText = string.Format(headerText, "username", "password");
    MessageHeader myHeader = MessageHeader.CreateHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", headerText, true);

    Because you are then saying the UsernameToken element and its children are of the "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" namespace.


    Jeff

    Monday, January 13, 2014 3:06 AM