1

I have archived put a SOAP header using this code using the CXF Runtimes

    //Create The Service
    URL wsdlURL = RentaCarService.WSDL_LOCATION;
    RentaCarService ss = new RentaCarService(wsdlURL, new QName("http://karve.com/", "RentaCarService"));
    RentaCar port = ss.getRentaCarPort();  

    //Create the header XML element
    List<Header> headers = new ArrayList<Header>();

    SOAPFactory sf = SOAPFactory.newInstance();
    SOAPElement seqElement = sf.createElement(new QName("http://karve.com/", "authentication"));
    seqElement.setPrefix("ns2");

    SOAPElement textElement = sf.createElement(new QName("", "companyNo"));
    textElement.addTextNode("00");
    seqElement.addChildElement(textElement);
    seqElement.setPrefix("ns2");

    SOAPElement textElement2 = sf.createElement(new QName("", "password"));
    textElement2.addTextNode("1234");
    seqElement.addChildElement(textElement2);
    seqElement.setPrefix("ns2");

    SoapHeader dummyHeader = new SoapHeader(new QName("", "any"), seqElement);        
    headers.add(dummyHeader);

    //Binding headers
    ((BindingProvider)port).getRequestContext().put(Header.HEADER_LIST, headers);

The result request its the following

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">

        <soap:Header>
            <ns2:authentication xmlns:ns2="http://karve.com/">
                <companyNo>00</companyNo>
                <password>1234</password>
            </ns2:authentication>
        </soap:Header>

        <soap:Body>
            <ns2:testRequest xmlns:ns2="http://karve.com/"/>
        </soap:Body>
    </soap:Envelope>

What I can do to generate the same request but the namespace definition in the envelope tag? I want generate a request like:

    <soap:Envelope 
            xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
            xmlns:ns2="http://karve.com/">

        <soap:Header>
            <ns2:authentication>
                <companyNo>00</companyNo>
                <password>1234</password>
            </ns2:authentication>
        </soap:Header>

        <soap:Body>
            <ns2:testRequest/>
        </soap:Body>
    </soap:Envelope>
josepmra
  • 617
  • 9
  • 25

0 Answers0