Creating PHP SOAP service from given WSDL
Asked Answered
P

3

9

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?

The receiver of the service is expecting a "User" object to be returned when the getMember method is invoked.

Here is the 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;
    }
}
Posticous answered 24/1, 2012 at 15:34 Comment(1)
Perhaps you should take a look at the classmap options of the options parameter of the SoapServer constructor...not sure but seems like a good place to look....Townsley
E
1

Have you tried SoapServer?

$server = new SoapServer('path/to/your.wsdl', $options);
Esquivel answered 24/1, 2012 at 16:2 Comment(5)
Hi, thanks. Yes I've tried that. This is what I currently have<br /> ` ini_set("soap.wsdl_cache_enabled", "0"); // Serve import( "site.amadeus.objects.amadeususer" ); $server = new SoapServer($this->getWsdlUrl()); $server->setClass( "User" ); $server->handle();` <br /> My User object has the getMember() method But all that replies is this:<br /> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"> <SOAP-ENV:Body> <ns1:getMemberResponse/> </SOAP-ENV:Body> </SOAP-ENV:Envelope>Posticous
No the request was successful but it just returned this <SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/soap/envelope" xmlns:ns1="tempuri.org"> <SOAP-ENV:Body> <ns1:getMemberResponse/> </SOAP-ENV:Body> </SOAP-ENV:Envelope> I need the response to look something like this <User><id>2</id><email>[email protected]</email>.......</User>Posticous
Thank you so much for your help. Here it is - 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; }Posticous
I think you might need to return a SoapParam object: return new SoapParam(array('id' => 2 'email' => ...), 'getMemberResponse');Esquivel
Hi, the SoapParam didnt seem to work but this has lead me on to SoapVar which I seem to be getting somewhere with. Thank you so much for your help.Posticous
A
3

At a basic level, you should be able to do the SOAP call with something like this (untested/pseudocode):

$client = new SoapClient("http://somesite/service.wsdl");
$result = $client->getMember();
var_dump($result);
Achaea answered 24/1, 2012 at 15:40 Comment(1)
Hi thanks for this but I need to create the server not the client. Do you have any ideas?Posticous
B
2

This is how it works for me :

//Instantiate server with relevant wsdl & class. 
$server = new SoapServer( 'mysoapwsdl.wsdl' );
$server->setClass(  'mysoapclass' );
$server->handle();
Bayles answered 10/11, 2014 at 1:58 Comment(0)
E
1

Have you tried SoapServer?

$server = new SoapServer('path/to/your.wsdl', $options);
Esquivel answered 24/1, 2012 at 16:2 Comment(5)
Hi, thanks. Yes I've tried that. This is what I currently have<br /> ` ini_set("soap.wsdl_cache_enabled", "0"); // Serve import( "site.amadeus.objects.amadeususer" ); $server = new SoapServer($this->getWsdlUrl()); $server->setClass( "User" ); $server->handle();` <br /> My User object has the getMember() method But all that replies is this:<br /> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"> <SOAP-ENV:Body> <ns1:getMemberResponse/> </SOAP-ENV:Body> </SOAP-ENV:Envelope>Posticous
No the request was successful but it just returned this <SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/soap/envelope" xmlns:ns1="tempuri.org"> <SOAP-ENV:Body> <ns1:getMemberResponse/> </SOAP-ENV:Body> </SOAP-ENV:Envelope> I need the response to look something like this <User><id>2</id><email>[email protected]</email>.......</User>Posticous
Thank you so much for your help. Here it is - 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; }Posticous
I think you might need to return a SoapParam object: return new SoapParam(array('id' => 2 'email' => ...), 'getMemberResponse');Esquivel
Hi, the SoapParam didnt seem to work but this has lead me on to SoapVar which I seem to be getting somewhere with. Thank you so much for your help.Posticous

© 2022 - 2024 — McMap. All rights reserved.