从给定的 WSDL 创建 PHP SOAP 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8989512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating PHP SOAP service from given WSDL
提问by mikedhart
This may come across as a terribly lazy question, but I assure you it is not. I have tried for days to get this working but I just cannot.
这可能是一个非常懒惰的问题,但我向你保证它不是。我已经尝试了几天才能使其正常工作,但我做不到。
I have been given a WSDL file and I need to create a SOAP service for it in PHP. Could any one tell me what the correct way of doing it is?
我得到了一个 WSDL 文件,我需要用 PHP 为它创建一个 SOAP 服务。谁能告诉我正确的做法是什么?
The receiver of the service is expecting a "User" object to be returned when the getMember method is invoked.
服务的接收者期望在调用 getMember 方法时返回一个“用户”对象。
Here is the WSDL
这是 WSDL
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="getMember">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="memCode" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getMemberResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="getMemberResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getMemberByUsernameAndPassword">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getMemberByUsernameAndPasswordResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="getMemberByUsernameAndPasswordResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="insertMember">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="insertStr" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="insertMemberResponse">
<s:complexType/>
</s:element>
<s:element name="decodeID">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="memCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="decodeIDResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="decodeIDResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="encodeID">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="memCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="encodeIDResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="encodeIDResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="processPnrInfo">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="pnrXml" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="UserXml" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="extraCosts" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="processPnrInfoResponse">
<s:complexType/>
</s:element>
<s:element name="CancelPNR">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="paxSurname" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="pnrNo" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="CancelPNRResponse">
<s:complexType/>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="getMemberSoapIn">
<wsdl:part name="parameters" element="tns:getMember"/>
</wsdl:message>
<wsdl:message name="getMemberSoapOut">
<wsdl:part name="parameters" element="tns:getMemberResponse"/>
</wsdl:message>
<wsdl:message name="getMemberByUsernameAndPasswordSoapIn">
<wsdl:part name="parameters" element="tns:getMemberByUsernameAndPassword"/>
</wsdl:message>
<wsdl:message name="getMemberByUsernameAndPasswordSoapOut">
<wsdl:part name="parameters" element="tns:getMemberByUsernameAndPasswordResponse"/>
</wsdl:message>
<wsdl:message name="insertMemberSoapIn">
<wsdl:part name="parameters" element="tns:insertMember"/>
</wsdl:message>
<wsdl:message name="insertMemberSoapOut">
<wsdl:part name="parameters" element="tns:insertMemberResponse"/>
</wsdl:message>
<wsdl:message name="decodeIDSoapIn">
<wsdl:part name="parameters" element="tns:decodeID"/>
</wsdl:message>
<wsdl:message name="decodeIDSoapOut">
<wsdl:part name="parameters" element="tns:decodeIDResponse"/>
</wsdl:message>
<wsdl:message name="encodeIDSoapIn">
<wsdl:part name="parameters" element="tns:encodeID"/>
</wsdl:message>
<wsdl:message name="encodeIDSoapOut">
<wsdl:part name="parameters" element="tns:encodeIDResponse"/>
</wsdl:message>
<wsdl:message name="processPnrInfoSoapIn">
<wsdl:part name="parameters" element="tns:processPnrInfo"/>
</wsdl:message>
<wsdl:message name="processPnrInfoSoapOut">
<wsdl:part name="parameters" element="tns:processPnrInfoResponse"/>
</wsdl:message>
<wsdl:message name="CancelPNRSoapIn">
<wsdl:part name="parameters" element="tns:CancelPNR"/>
</wsdl:message>
<wsdl:message name="CancelPNRSoapOut">
<wsdl:part name="parameters" element="tns:CancelPNRResponse"/>
</wsdl:message>
<wsdl:portType name="ServiceSoap">
<wsdl:operation name="getMember">
<wsdl:input message="tns:getMemberSoapIn"/>
<wsdl:output message="tns:getMemberSoapOut"/>
</wsdl:operation>
<wsdl:operation name="getMemberByUsernameAndPassword">
<wsdl:input message="tns:getMemberByUsernameAndPasswordSoapIn"/>
<wsdl:output message="tns:getMemberByUsernameAndPasswordSoapOut"/>
</wsdl:operation>
<wsdl:operation name="insertMember">
<wsdl:input message="tns:insertMemberSoapIn"/>
<wsdl:output message="tns:insertMemberSoapOut"/>
</wsdl:operation>
<wsdl:operation name="decodeID">
<wsdl:input message="tns:decodeIDSoapIn"/>
<wsdl:output message="tns:decodeIDSoapOut"/>
</wsdl:operation>
<wsdl:operation name="encodeID">
<wsdl:input message="tns:encodeIDSoapIn"/>
<wsdl:output message="tns:encodeIDSoapOut"/>
</wsdl:operation>
<wsdl:operation name="processPnrInfo">
<wsdl:input message="tns:processPnrInfoSoapIn"/>
<wsdl:output message="tns:processPnrInfoSoapOut"/>
</wsdl:operation>
<wsdl:operation name="CancelPNR">
<wsdl:input message="tns:CancelPNRSoapIn"/>
<wsdl:output message="tns:CancelPNRSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getMember">
<soap:operation soapAction="http://tempuri.org/getMember" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getMemberByUsernameAndPassword">
<soap:operation soapAction="http://tempuri.org/getMemberByUsernameAndPassword" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="insertMember">
<soap:operation soapAction="http://tempuri.org/insertMember" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="decodeID">
<soap:operation soapAction="http://tempuri.org/decodeID" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="encodeID">
<soap:operation soapAction="http://tempuri.org/encodeID" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="processPnrInfo">
<soap:operation soapAction="http://tempuri.org/processPnrInfo" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CancelPNR">
<soap:operation soapAction="http://tempuri.org/CancelPNR" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getMember">
<soap12:operation soapAction="http://tempuri.org/getMember" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getMemberByUsernameAndPassword">
<soap12:operation soapAction="http://tempuri.org/getMemberByUsernameAndPassword" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="insertMember">
<soap12:operation soapAction="http://tempuri.org/insertMember" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="decodeID">
<soap12:operation soapAction="http://tempuri.org/decodeID" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="encodeID">
<soap12:operation soapAction="http://tempuri.org/encodeID" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="processPnrInfo">
<soap12:operation soapAction="http://tempuri.org/processPnrInfo" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="CancelPNR">
<soap12:operation soapAction="http://tempuri.org/CancelPNR" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service">
<wsdl:port name="ServiceSoap" binding="tns:ServiceSoap">
<soap:address location="[byng_wsdl_target]"/>
</wsdl:port>
<wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12">
<soap12:address location="[byng_wsdl_target]"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I would be so grateful for anyone who can help.
我将非常感谢任何可以提供帮助的人。
ADDITIONAL
额外的
class User {
public $GuestUserId;
public $Username;
public $FirstName;
public $SurName;
public $Email;
public
function getMember($uid) {
$applicant = new Applicant($uid);
$this->GuestUserId = $applicant->getIdentifier();
$this->Username = $applicant->getEmail();
$this->FirstName = $applicant->getFirstName();
$this->SurName = $applicant->getLastName();
$this->Email = $applicant->getEmail();
return $this;
}
}
采纳答案by Rob Agar
回答by Jeremy Harris
At a basic level, you should be able to do the SOAP call with something like this (untested/pseudocode):
在基本级别上,您应该能够使用以下内容(未经测试/伪代码)进行 SOAP 调用:
$client = new SoapClient("http://somesite/service.wsdl");
$result = $client->getMember();
var_dump($result);
回答by Gucho Ca
This is how it works for me :
这对我来说是这样的:
//Instantiate server with relevant wsdl & class.
$server = new SoapServer( 'mysoapwsdl.wsdl' );
$server->setClass( 'mysoapclass' );
$server->handle();