带有名称空间的CXF soap标头,分组为Envelope标记

时间:2015-04-30 18:05:24

标签: web-services cxf xml-namespaces soapheader

我已使用CXF运行时

使用此代码存档了一个SOAP标头
    //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);

结果请求以下

    <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>

我可以做些什么来生成相同的请求,但信封标签中的命名空间定义? 我想生成一个请求:

    <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>

0 个答案:

没有答案