我正在尝试创建一个soapMessage,以便稍后传递到以下代码段:
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
SOAPMessage response = connection.call(message, url);
但是,我收到一个空(null)响应:[SOAP-ENV:Body:null]。
当我执行以下操作时(在连接调用之前):
System.out.println(message.getSOAPBody());
message.writeTo(System.out);
当它们应该相同时,我得到两个不同的响应,对吗?
第一个系统 print ln 给了我 [SOAP-ENV:Body: null],而另一个实际上给了我我创建的肥皂消息 (writeTo)。
任何想法为什么?
完整代码:
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
SOAPElement tvl = envelope.addAttribute(new QName("xmlns:tvl"), "http://some.url.com/");
SOAPBody body = message.getSOAPBody();
QName bodyText = new QName("tvl:searchAirings");
SOAPBodyElement bodyElement = body.addBodyElement(bodyText);
QName fromTag = new QName("from");
SOAPElement from = bodyElement.addChildElement(fromTag);
from.setValue("2012-11-02T14:00:00-4:00");
QName toTag = new QName("to");
SOAPElement to = bodyElement.addChildElement(toTag);
to.setValue("2012-11-02T18:00:00-4:00");
QName networkTag = new QName("network");
SOAPElement network = bodyElement.addChildElement(networkTag);
network.setAttribute("id", "n501");
network.setAttribute("language", "es");
System.out.println(message.getSOAPBody());
message.writeTo(System.out);