我已经提供了一个.wsdl-URI和一个Java示例(见下文),需要通过SSL进行SOAP调用并处理响应。我使用PHP和Zend Framework,但无法弄清楚从哪里开始。我早些时候使用C#.NET调用SOAP服务,但通过向导配置服务后,只需要2-3行代码。有没有简单的方法来进行调用并处理结果XML?如果没有,我可以在哪里找到一个很好的例子让我开始?使用Zend框架通过SSL进行SOAP调用
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());
}
}
}
你有什么尝试过,发布你的尝试和输出的PHP代码示例... – danielrsmith 2012-03-15 15:31:24
我试过什么都没有,因为我不知道从哪里开始。正如Tim所评论的那样,有一些文档是zend.com,但没有任何内容适用于我正在做的事情。如何将命名参数发送到SOAP函数调用?如何添加不同的节点,例如Java示例呢?我会根据这个例子编写一个简单的3行事件来证明我已经尝试过了,但我不确定这个讨论有多大的价值。我的意思是...... Java的例子甚至没有在任何地方使用WSDL文件。 – rymored 2012-03-15 22:27:05
'Zend_Soap_Client'扩展了通用PHP'SoapClient'看看它的文档http://us3.php.net/manual/en/soapclient.soapclient.php – danielrsmith 2012-03-16 21:24:19