【问题标题】:Add namespace prefix Axis2添加命名空间前缀 Axis2
【发布时间】:2013-07-04 16:17:47
【问题描述】:

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

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

【问题讨论】:

  • 您需要查看应该显示您想要发送到服务的内容的 XML sn-p。它混合了 SOAP 1.1 和 SOAP 1.2,并且没有 sear 前缀的命名空间声明。因此是无效的。我怀疑 sn-p 显示的是代码的实际输出,而不是您要生成的消息。

标签: java web-services soap axis2


【解决方案1】:
envelope.addNamespaceDeclaration("sear", "http://search");

【讨论】:

  • 方法addNamespaceDeclaration()不存在。改用envelope.declareNamespace("URI","Prefix")
【解决方案2】:
    OMNamespace xsi = soapFactory.createOMNamespace(
            Constants.URI_DEFAULT_SCHEMA_XSI,
            Constants.NS_PREFIX_SCHEMA_XSI);

    envelope.declareNamespace(xsi);

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多