2013-07-04 238 views
0

这是信封,我想送服务:添加命名空间前缀的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); 

但没有规定我的命名空间前缀“烧焦” 。 如何在代码中设置它以获取

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

in XML?

+0

更多信息,您需要检查是应该告诉你要发送到的服务是什么XML片段。它混合使用了SOAP 1.1和SOAP 1.2,并且没有用于'sear'前缀的名称空间声明。因此它是无效的。我怀疑这段代码显示了代码的实际输出,而不是你想要生成的消息。 –

回答

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

“addNamespaceDeclaration()”方法不存在。改用'envelope.declareNamespace(“URI”,“Prefix”)' – vkrams