Java生成SOAP信封 [英] Java Generate SOAP Envelope
问题描述
我有以下方法:
String [] getEmployeeDetails(int employeeNumber);
关联请求如下所示:
String[] getEmployeeDetails ( int employeeNumber ); The assosiate request look like this :
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:getEmployeeDetails
xmlns:ns1="urn:MySoapServices">
<param1 xsi:type="xsd:int">1016577</param1>
</ns1:getEmployeeDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这个例子来自此链接[ http://www.soapuser.com/basics3.html] [1]
this example come from this link [http://www.soapuser.com/basics3.html][1]
我不明白他们如何使用java以编程方式生成它。
请帮忙!
I don't understand how they do to generate it programtically with java. Please help !
推荐答案
基本上你需要使用SAAJ API,这是一个使用SOAPMessage并给你的API一些以编程方式创建SOAP请求的对象和方法,你可以看到这个链接以供进一步参考。另请查看Oracle的文档,它们为您提供了一些有用的信息例子。例如,您可以查看 link
Basically you need to use SAAJ API, this is an API that use SOAPMessage and give you some objects and methods to create SOAP request programatically, you shouls see this link for further reference. Also review the documentation from Oracle, they give you some useful examples. For real example you could check this link
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
// Retrieve different parts
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
// Two ways to extract headers
SOAPHeader soapHeader = soapEnvelope.getHeader();
soapHeader = soapMessage.getSOAPHeader();
// Two ways to extract body
SOAPBody soapBody = soapEnvelope.getBody();
soapBody = soapMessage.getSOAPBody();
// To add some element
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name bodyName = soapFactory.createName("getEmployeeDetails","ns1","urn:MySoapServices");
SOAPBodyElement purchaseLineItems = soapBody.addBodyElement(bodyName);
Name childName = soapFactory.createName("param1");
SOAPElement order = purchaseLineItems.addChildElement(childName);
order.addTextNode("1016577");
这篇关于Java生成SOAP信封的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!