java - 添加命名空间前缀 Axis2

标签 java web-services soap apache-axis

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

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

最佳答案

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

关于java - 添加命名空间前缀 Axis2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17474691/

相关文章:

java - 如何在 StreamingOutput 的 Web 服务中保持客户端和服务器连接处于 Activity 状态

java - 后台线程阻止 Tomcat 7 应用程序启动

REST 与 SOAP - SOAP 真的比 REST 更安全吗?

java - 如何使用 jersey 和 json 在 java 中检索 Restful Web 服务的有效负载数据

java - 尝试通过 Selenium 和 Java 使用 sendKeys 时获取验证消息

java - 为什么最终变量不总是一个常量表达式?

java - 在 JAVA 中使用基于安全 SOAP 的 Web 服务时出错

javascript - IOS 上的 xmlhttprequest 不发送请求?

c# - 通过 Soap 传递数字数组

java - 字节流中字符的数字索引