gpt4 book ai didi

Java 生成 SOAP 信封

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:09:14 28 4
gpt4 key购买 nike

我有以下方法:

字符串[] getEmployeeDetails ( int employeeNumber ); 关联请求如下所示:

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

我不明白他们如何使用 java 以编程方式生成它。请帮忙!

最佳答案

基本上您需要使用 SAAJ API,这是一个使用 SOAPMessage 并为您提供一些对象和方法以编程方式创建 SOAP 请求的 API,您应该查看 this链接以供进一步引用。还要查看 documentation来自 Oracle,他们为您提供了一些有用的示例。对于真实示例,您可以查看此 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 信封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28570086/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com