Add a header to a SOAP HTTP request

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moorcroft
    New Member
    • Mar 2008
    • 57

    #1

    Add a header to a SOAP HTTP request

    OK I have java code which creates the following XML SOAP message:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header/>
    <soap-env:Body>
    <GetAppList xmlns="https://***.***.***.***/***/***.asmx">
    <requestId>1</requestId>
    <laNumber>5</laNumber>
    <hashCode>123456</hashCode>
    </GetAppList>
    </soap-env:Body></soap-env:Envelope>
    I need the message to have a header before the xml code so it would look like:

    Code:
    Host: ***.***.***.***
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://***.***.***.***/***/***"
    
    <?xml version="1.0" encoding="UTF-8"?>
    <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Header/><soap-env:Body><GetAppList xmlns="https://***.***.***.***/***/***.asmx">
    <requestId>1</requestId>
    <laNumber>5</laNumber>
    <hashCode>123456</hashCode>
    </GetAppList>
    </soap-env:Body></soap-env:Envelope>
    The java code I have used to create this message is as follows:

    Code:
    MessageFactory factory  = MessageFactory.newInstance();
                SOAPMessage message     = factory.createMessage();
                SOAPPart soapPart       = message.getSOAPPart();
                SOAPEnvelope envelope   = soapPart.getEnvelope();
                
                SOAPBody body           = envelope.getBody();
                
                SOAPFactory soapFactory 			= SOAPFactory.newInstance();
                Name bodyName                      	= soapFactory.createName("GetAppList","","https://***.***.***.***/***/***.asmx");
                SOAPBodyElement bodyElement   		= body.addBodyElement(bodyName);
                
                
                //Create nodes for sending requestId, laNumber and hashCode
                Name nameRequestId = soapFactory.createName("requestId");
                SOAPElement requestId = bodyElement.addChildElement(nameRequestId);
    			requestId.addTextNode("1");
    
    			Name nameLaNumber = soapFactory.createName("laNumber");
                SOAPElement laNumber = bodyElement.addChildElement(nameLaNumber);
    			laNumber.addTextNode(lpaCode);
    
    			Name nameHashCode = soapFactory.createName("hashCode");
                SOAPElement hashCode = bodyElement.addChildElement(nameHashCode);
    			hashCode.addTextNode(encryptedHashCode);
    Could someone please help me out!
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Looks like you're pretty savvy at this stuff, if you can create such a message. Any errors at all, or you just don't know how to get a header...

    Sorry for your troubles!

    Comment

    Working...