添加名称空间前缀Axis2

时间:2013-07-04 16:17:47

标签: java web-services soap axis2

这是我想发送给服务的信封:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
        <sear:searchUrls>
            <sear:in0>Safeway, 200 S. 3rd St, Renton, WA</sear:in0>
        </sear:searchUrls>
    </soapenv:Body>
</soapenv:Envelope>

这是构建它的代码:

SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
SOAPEnvelope envelope = fac.getDefaultEnvelope();

OMNamespace omNs = fac.createOMNamespace("http://schemas.xmlsoap.org/soap/envelope/", "soapenv");
OMNamespace ns1 = fac.createOMNamespace("http://search", "sear");

envelope.setNamespace(omNs);

OMNamespace ns = fac.createOMNamespace("", "")
OMElement method = fac.createOMElement("sear:searchUrls", ns);
OMElement value = fac.createOMElement("sear:in0", ns);
value.setText("Safeway, 200 S. 3rd St, Renton, WA");
method.addChild(value);
envelope.getBody().addChild(method);

但我的名称空间前缀“sear”未定义。 如何在代码中设置它来获取

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sear="http://search">
XML中的

2 个答案:

答案 0 :(得分:1)

envelope.addNamespaceDeclaration("sear", "http://search");

答案 1 :(得分:0)

您是否拥有WSDL并知道终点网址? 您可以使用wsdl2java转换器生成客户端代码。

http://axis.apache.org/axis2/java/core/docs/userguide-creatingclients.html#choosingclient

的更多信息