0

这是我想送去服务的信封:

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

4

3 回答 3

2
envelope.addNamespaceDeclaration("sear", "http://search");
于 2013-07-10T20:19:57.417 回答
1
    OMNamespace xsi = soapFactory.createOMNamespace(
            Constants.URI_DEFAULT_SCHEMA_XSI,
            Constants.NS_PREFIX_SCHEMA_XSI);

    envelope.declareNamespace(xsi);
于 2022-01-13T04:54:01.783 回答
0

你有 WSDL 并且知道端点 url 吗?您可以使用 wsdl2java 转换器生成客户端代码。

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

于 2013-07-05T22:24:41.320 回答