gpt4 book ai didi

php - 使用 Zend Framework 通过 SSL 进行 SOAP 调用

转载 作者:太空宇宙 更新时间:2023-11-03 15:15:03 25 4
gpt4 key购买 nike

我已经获得了一个 .wsdl-URI 和一个 Java 示例(见下文)并且需要通过 SSL 进行 SOAP 调用并处理响应。我正在使用 PHP 和 Zend Framework,但不知道从哪里开始。我之前使用 C#.NET 调用过 SOAP 服务,但在通过向导配置服务后只需要 2-3 行代码。是否有一种简单的方法来进行此调用并处理生成的 XML?如果没有,我在哪里可以找到一个很好的例子来帮助我入门?

import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPHeader;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;

public class RegistryDetails {
private static final long serialVersionUID= 1L;
private static final String SERVICE = "https://ServiceProvider.com/TheService.pl";
private static final String TAG_GETPRODUCT = "getDetails";
private static String namespaceService = "http://ServiceProvider.com/TheService.xsd";
private static String namespaceUserSession = "http://ServiceProvider.com/UserSession.xsd";
private static String SYSTEM = "thesystem";
private static String USERNAME = "theusername";
private static String PASSWORD = "thepassword";

public static void main(String[] args) {

try {

//Create the connection
SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnFactory.createConnection();

//Create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();

MimeHeaders mimeHeader = message.getMimeHeaders();
mimeHeader.addHeader("SOAPAction", "");

//Create objects for the message parts
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();

SOAPHeader header = envelope.getHeader();
SOAPElement userSession = header.addChildElement("UserSession", "UserSession", namespaceUserSession);

userSession.addChildElement("TypeOfService").addTextNode("Integrated");
userSession.addChildElement("System").addTextNode(SYSTEM);
userSession.addChildElement("Username").addTextNode(USERNAME);
userSession.addChildElement("Password").addTextNode(PASSWORD);

SOAPBody body = envelope.getBody();

//Populate the body
//Create the main element and namespace
SOAPElement getDetails = body.addChildElement(TAG_GETPRODUCT, "dfg", namespaceService);

getDetails.addChildElement("queryField1").addTextNode("xxx");
getDetails.addChildElement("queryField2").addTextNode("yyy");
getDetails.addChildElement("queryField3").addTextNode("zzz");

//Save the message
message.saveChanges();

//Check the input
System.out.println("\nREQUEST:\n");
message.writeTo(System.out);
System.out.println();

//Send the message and get a reply

//Send the message
SOAPMessage reply = connection.call(message, SERVICE);

System.out.println("\nRESPONSE:\n");
reply.writeTo(System.out);
System.out.println();

{
SOAPBody retbody = reply.getSOAPBody();
if (retbody.hasFault()) {
SOAPFault fault = retbody.getFault();
System.out.println("SOAPfault: " + fault.getFaultString());
}
else {
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("*/RESULT/HOV/ReturnField1");
String returnField1 = (String)expr.evaluate(retbody, XPathConstants.STRING);
System.out.println("Result: " + returnField1);
}
}

//Close the connection
connection.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

最佳答案

http://framework.zend.com/manual/en/zend.soap.client.html - 传入您的 WSDL URL,然后您可以根据需要进行调用。

关于php - 使用 Zend Framework 通过 SSL 进行 SOAP 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9720965/

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