简体   繁体   English

JAVA Webservice SOAP客户端如何设置xmlns方法属性?

[英]JAVA Webservice SOAP Client How to set xmlns method attribute?

I implemented a soap client to call a web service method of a third person. 我实现了一个肥皂客户端来调用第三方的Web服务方法。 The method is: InsertData_Str 该方法是:InsertData_Str

I've a problem with my java application. 我的Java应用程序有问题。 I need to add to the InsertData_Str method the xmlns attribute but it doesn't work, it put an empty value and I don't understand why. 我需要将xmlns属性添加到InsertData_Str方法中,但是它不起作用,它放置了一个空值,我不明白为什么。 Any idea? 任何想法?

Here is the code: 这是代码:

MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
soapMessage.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
soapMessage.setContentDescription("MY Connector");

SOAPPart soapPart = soapMessage.getSOAPPart();

String serverURI = "http://www.ik.com/ikConnect";

// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();

envelope.setPrefix("soap");
SOAPBody soapBody = envelope.getBody();

SOAPElement soapMethod = soapBody.addChildElement("InsertData_Str"); //Method
//soapMethod.setAttribute("xmlns", "http://www.ik.com/ikConnect"); //This doesn't work
QName attributeName = new QName("xmlns");
soapMethod.addAttribute(attributeName,"http://www.ik.com/ikConnect"); //If I Debugg I can see that xmln attribute is OK but when the message is sent xmln is empty

Here is the output: 这是输出:

<?xml version="1.0" encoding="utf-8" ?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><InsertData_Str xmlns=""><xdoc xmlns="http://www.ik.com/ikConnect">TEST</xdoc></InsertData_Str></SOAP-ENV:Body></soap:Envelope>

I solved it. 我解决了 I changed SOAPElement addChildElement(String localName) method by this other one addChildElement(String localName,String prefix,String uri) 我通过另一个addChildElement(String localName,String prefix,String uri)更改了SOAPElement addChildElement(String localName)方法

Example: 例:

String serverURI = "http://www.ik.com/ikConnect";
SOAPElement soapMethod = soapBody.addChildElement("InsertData_Str", "", serverURI); 

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

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