简体   繁体   English

添加命名空间前缀 Axis2

[英]Add namespace prefix Axis2

This is envelope which i wanna to send to service:这是我想送去服务的信封:

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

And this is code to construct it:这是构造它的代码:

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

But my namespace prefix "sear" is not defined.但是我的命名空间前缀“sear”没有定义。 How can I set it in code to get如何在代码中设置它以获取

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

in XML?在 XML 中?

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

Do you have the WSDL and know the end point url ? 您是否拥有WSDL并知道终点URL? You can generate the client side code using the wsdl2java convertor. 您可以使用wsdl2java转换器生成客户端代码。

More information at http://axis.apache.org/axis2/java/core/docs/userguide-creatingclients.html#choosingclient 有关更多信息,请访问http://axis.apache.org/axis2/java/core/docs/userguide-creatingclients.html#choosingclient

    OMNamespace xsi = soapFactory.createOMNamespace(
            Constants.URI_DEFAULT_SCHEMA_XSI,
            Constants.NS_PREFIX_SCHEMA_XSI);

    envelope.declareNamespace(xsi);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM