How to generate a response that matches wsdl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nickweavers
    New Member
    • Feb 2007
    • 6

    How to generate a response that matches wsdl

    Hi, I have a wsdl I have to conform to that looks like this:
    Code:
    <?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://www.paaleads.com/LeadConsumerService/"
    	xmlns:s="http://www.w3.org/2001/XMLSchema"
    	xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    	xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        targetNamespace="http://www.paaleads.com/LeadConsumerService/">
    
      	<wsdl:types>
        	<s:schema elementFormDefault="qualified" targetNamespace="http://www.paaleads.com/LeadConsumerService/">
          		<s:element name="ConsumeLead">
            		<s:complexType>
              			<s:sequence>
                			<s:element minOccurs="0" maxOccurs="1" name="request" type="tns:ConsumeLeadRequest" />
              			</s:sequence>
            		</s:complexType>
          		</s:element>
          		<s:complexType name="ConsumeLeadRequest">
            		<s:sequence>
              			<s:element minOccurs="1" maxOccurs="1" name="LeadType" type="tns:LeadType" />
              			<s:element minOccurs="0" maxOccurs="1" name="LeadXml" type="s:string" />
              			<s:element minOccurs="0" maxOccurs="1" name="AuthenticationUsername" type="s:string" />
              			<s:element minOccurs="0" maxOccurs="1" name="AuthenticationPassword" type="s:string" />
            		</s:sequence>
          		</s:complexType>
          		<s:simpleType name="LeadType">
            		<s:restriction base="s:string">
              			<s:enumeration value="Unknown" />
              			<s:enumeration value="Mortgage" />
              			<s:enumeration value="TermAssurance" />
              			<s:enumeration value="Travel" />
              			<s:enumeration value="PMI" />
              			<s:enumeration value="SecuredLoan" />
              			<s:enumeration value="CreditHelp" />
              			<s:enumeration value="Stakeholder" />
              			<s:enumeration value="TermPostal" />
              			<s:enumeration value="Pension" />
              			<s:enumeration value="Savings" />
              			<s:enumeration value="Investments" />
              			<s:enumeration value="UnsecuredLoan" />
              			<s:enumeration value="OverseasMortgage" />
              			<s:enumeration value="Debt" />
              			<s:enumeration value="ASU" />
              			<s:enumeration value="LegalServices" />
            		</s:restriction>
          		</s:simpleType>
          		<s:element name="ConsumeLeadResponse">
            		<s:complexType>
              			<s:sequence>
                			<s:element minOccurs="0" maxOccurs="1" name="ConsumeLeadResult" type="tns:ConsumeLeadResponse" />
              			</s:sequence>
            		</s:complexType>
          		</s:element>
          		<s:complexType name="ConsumeLeadResponse">
            		<s:sequence>
              			<s:element minOccurs="1" maxOccurs="1" name="LeadReceived" type="s:boolean" />
              			<s:element minOccurs="0" maxOccurs="1" name="FailureMessage" type="s:string" />
            		</s:sequence>
          		</s:complexType>
        	</s:schema>
      	</wsdl:types>
    	<wsdl:message name="ConsumeLeadSoapIn">
        	<wsdl:part name="parameters" element="tns:ConsumeLead" />
      	</wsdl:message>
      	<wsdl:message name="ConsumeLeadSoapOut">
        	<wsdl:part name="parameters" element="tns:ConsumeLeadResponse" />
      	</wsdl:message>
    
      	<wsdl:portType name="LeadConsumerServiceSoap">
        	<wsdl:operation name="ConsumeLead">
          		<wsdl:input message="tns:ConsumeLeadSoapIn" />
          		<wsdl:output message="tns:ConsumeLeadSoapOut" />
        	</wsdl:operation>
      	</wsdl:portType>
    
      	<wsdl:binding name="LeadConsumerServiceSoap" type="tns:LeadConsumerServiceSoap">
        	<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
        	<wsdl:operation name="ConsumeLead">
          		<soap:operation soapAction="http://www.paaleads.com/LeadConsumerService/ConsumeLead" 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="LeadConsumerServiceSoap12" type="tns:LeadConsumerServiceSoap">
        	<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
        	<wsdl:operation name="ConsumeLead">
          		<soap12:operation soapAction="http://www.paaleads.com/LeadConsumerService/ConsumeLead" 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="LeadConsumerService">
        	<wsdl:port name="LeadConsumerServiceSoap" binding="tns:LeadConsumerServiceSoap">
          		<soap:address location="http://localhost:8080/dealdirectfinancial.co.uk/paaleads/PAALeadServer.php" />
        	</wsdl:port>
        	<wsdl:port name="LeadConsumerServiceSoap12" binding="tns:LeadConsumerServiceSoap12">
          		<soap12:address location="http://localhost:8080/dealdirectfinancial.co.uk/paaleads/PAALeadServer.php" />
        	</wsdl:port>
      	</wsdl:service>
    </wsdl:definitions>
    At the moment I can get my input to pass the wsdl, but I can't seem to pass a response back.
    My server code looks like this:
    Code:
    <?php
    # PAALeadServer.php
    # SiteWeavers Web Solutions (http:www.siteweavers.co.uk)
    #
    
    function ConsumeLead($data) 
    
    	$response =
    		array(
    			'ConsumeLeadResponse' =>
    				array(
    					'ConsumeLeadResult' =>
    						array(
    	   						'LeadReceived' => 'true'
    						)
    				)
    			);
       return $response;
    }
    
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new SoapServer("http://localhost:8080/dealdirectfinancial.co.uk/paaleads/LeadConsumerService.wsdl");
    $server->addFunction("ConsumeLead");
    
    $server->handle();
    ?>
    My client like this:
    Code:
    <?php
    
       $leadType = 'Mortgage';
    
       $leadXML = '
    	&lt;ns1:LeadAssigned xmlns:ns1="http://PAA.LeadDelivery.Generic.Schemas.LeadAssigned" xmlns:ns0="http://PAA.LeadDelivery.Generic.Schemas.Lead" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    		&lt;ns0:Lead&gt;
    			&lt;Reference&gt;
    				1234
    			&lt;/Reference&gt;
    			&lt;Product&gt;
    				&lt;Mnemonic&gt;
    					Mortgage
    				&lt;/Mnemonic&gt;
    				&lt;Description&gt;
    					Mortgage Leads
    				&lt;/Description&gt;
    				&lt;SubType&gt;
    					Other
    				&lt;/SubType&gt;
    			&lt;/Product&gt;
    			&lt;ExtendedInfo&gt;
    				&lt;Mortgage&gt;
    					&lt;MortgageValue&gt;
    						75000
    					&lt;/MortgageValue&gt;
    					&lt;MortgageValueLowerBound&gt;
    						1
    					&lt;/MortgageValueLowerBound&gt;
    					&lt;MortgageValueUpperBound&gt;
    						500
    					&lt;/MortgageValueUpperBound&gt;
    					&lt;PropertyValue&gt;
    						100000
    					&lt;/PropertyValue&gt;
    					&lt;PropertyValueLowerBound&gt;
    						1
    					&lt;/PropertyValueLowerBound&gt;
    					&lt;PropertyValueUpperBound&gt;
    						500
    					&lt;/PropertyValueUpperBound&gt;
    					&lt;Adverse&gt;
    						false
    					&lt;/Adverse&gt;
    					&lt;FirstTime&gt;
    						false
    					&lt;/FirstTime&gt;
    				&lt;/Mortgage&gt;
    			&lt;/ExtendedInfo&gt;
    			&lt;Applicants&gt;
    				&lt;Applicant1&gt;
    					&lt;Title&gt;
    						Mr
    					&lt;/Title&gt;
    					&lt;Forename&gt;
    						SampleForename
    					&lt;/Forename&gt;
    					&lt;Surname&gt;
    						SampleSurname
    					&lt;/Surname&gt;
    					&lt;DateOfBirth&gt;
    						1903-02-01
    					&lt;/DateOfBirth&gt;
    					&lt;Smoker&gt;
    						false
    					&lt;/Smoker&gt;
    					&lt;TelephoneNumbers&gt;
    						&lt;TelephoneNumber&gt;
    							&lt;Number&gt;
    								01244123456
    							&lt;/Number&gt;
    							&lt;Type&gt;
    								Mobile
    							&lt;/Type&gt;
    						&lt;/TelephoneNumber&gt;
    					&lt;/TelephoneNumbers&gt;
    					&lt;EmailAddresses&gt;
    						&lt;EmailAddress&gt;
    							&lt;Email&gt;
    								test@moneysupermarket.com
    							&lt;/Email&gt;
    							&lt;Type&gt;
    								Business
    							&lt;/Type&gt;
    						&lt;/EmailAddress&gt;
    					&lt;/EmailAddresses&gt;
    					&lt;Addresses&gt;
    						&lt;Address&gt;
    							&lt;Street&gt;
    								Sample Street
    							&lt;/Street&gt;
    							&lt;District&gt;
    								Sample District
    							&lt;/District&gt;
    							&lt;Town&gt;
    								Sample Town
    							&lt;/Town&gt;
    							&lt;County&gt;
    								Sample County
    							&lt;/County&gt;
    							&lt;Postcode&gt;
    								CH53UZ
    							&lt;/Postcode&gt;
    							&lt;Type&gt;
    								Home
    							&lt;/Type&gt;
    						&lt;/Address&gt;
    					&lt;/Addresses&gt;
    				&lt;/Applicant1&gt;
    			&lt;/Applicants&gt;
    		&lt;/ns0:Lead&gt;
    		&lt;Assignment&gt;
    			&lt;Price&gt;
    				20
    			&lt;/Price&gt;
    			&lt;AssignmentDateTime&gt;
    				2010-02-01T00:00:00
    			&lt;/AssignmentDateTime&gt;
    			&lt;Subscription&gt;
    				&lt;Reference&gt;
    					1234
    				&lt;/Reference&gt;
    				&lt;Subscriber&gt;
    					&lt;Title&gt;
    						Mr
    					&lt;/Title&gt;
    					&lt;Forename&gt;
    						SampleForename
    					&lt;/Forename&gt;
    					&lt;Surname&gt;
    						SampleSurname
    					&lt;/Surname&gt;
    				&lt;/Subscriber&gt;
    			&lt;/Subscription&gt;
    			&lt;Account&gt;
    				&lt;Reference&gt;
    					1234
    				&lt;/Reference&gt;
    				&lt;CompanyName&gt;
    					Sample Company
    				&lt;/CompanyName&gt;
    			&lt;/Account&gt;
    			&lt;LeadType&gt;
    				SampleLeadType
    			&lt;/LeadType&gt;
    			&lt;TerritoryName&gt;
    				UNITED KINGDOM
    			&lt;/TerritoryName&gt;
    		&lt;/Assignment&gt;
    	&lt;/ns1:LeadAssigned&gt;
        ';
    
    	$server = "http://localhost:8080/dealdirectfinancial.co.uk/paaleads/";
    	$wsdl = $server . "LeadConsumerService.wsdl";
    
    	try {
       		$client = new SoapClient($wsdl,
          		array("trace"=>1,"exceptions"=>1));
    
    
            ob_start();
            var_dump($client->__getFunctions());
            $dump = ob_get_contents();
            ob_end_clean();
    
       		printf("<br />Dumping client object functions:<br /><pre>%s</pre>", $dump);
    
       		// Create the parameters
    
    		$params =
    			array(
    				'ConsumeLead' =>
    					array( 'request' =>
    						array(
    							"LeadType" => $leadType,
    							"LeadXml" => $leadXML,
    							"AuthenticationUsername" => 'dealdirectfinancial',
    							"AuthenticationPassword" => 'opensesame'
    						)
    					)
    				);
    		//$params = array(new SoapParam($params, 'ConsumeLeadRequest'));
    
       		// Make the call to the service
            #$result = $client->ConsumeLead($params);
            $result = $client->__soapCall('ConsumeLead', $params);
    
            // Print the result
            printf("Printing the response: <br /><br />");
            print_r($result->ConsumeLeadResponse);
    
        } catch (SoapFault $e) {
            echo "Error: {$e->faultstring}";
        }
    // display what was sent to the server (the request)
    printf("Request: %s <br />", htmlspecialchars($client->__getLastRequest()));
    // display what came back from the server (the response)
    printf("Response: %s <br />", htmlspecialchars($client->__getLastResponse()));
    ?>
    The output I see shows the request xml gets generated correctly, but the response xml just has a closing tag for the output parameters and the php debugger shows
    Code:
     $result: object(stdClass) =
    ie. the result appears to be an empty object of stdClass.
    The output is as follows:
    Code:
    Dumping client object functions:
    
    array(2) {
      [0]=>
      string(56) "ConsumeLeadResponse ConsumeLead(ConsumeLead $parameters)"
      [1]=>
      string(56) "ConsumeLeadResponse ConsumeLead(ConsumeLead $parameters)"
    }
    
    Printing the response:
    
    Request: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.paaleads.com/LeadConsumerService/"><SOAP-ENV:Body><ns1:ConsumeLead><ns1:request><ns1:LeadType>Mortgage</ns1:LeadType><ns1:LeadXml>
     &amp;lt;ns1:LeadAssigned xmlns:ns1="http://PAA.LeadDelivery.Generic.Schemas.LeadAssigned" xmlns:ns0="http://PAA.LeadDelivery.Generic.Schemas.Lead" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&amp;gt;
     &amp;lt;ns0:Lead&amp;gt;
     &amp;lt;Reference&amp;gt;
     1234
     &amp;lt;/Reference&amp;gt;
     &amp;lt;Product&amp;gt;
     &amp;lt;Mnemonic&amp;gt;
     Mortgage
     &amp;lt;/Mnemonic&amp;gt;
     &amp;lt;Description&amp;gt;
     Mortgage Leads
     &amp;lt;/Description&amp;gt;
     &amp;lt;SubType&amp;gt;
     Other
     &amp;lt;/SubType&amp;gt;
     &amp;lt;/Product&amp;gt;
     &amp;lt;ExtendedInfo&amp;gt;
     &amp;lt;Mortgage&amp;gt;
     &amp;lt;MortgageValue&amp;gt;
     75000
     &amp;lt;/MortgageValue&amp;gt;
     &amp;lt;MortgageValueLowerBound&amp;gt;
     1
     &amp;lt;/MortgageValueLowerBound&amp;gt;
     &amp;lt;MortgageValueUpperBound&amp;gt;
     500
     &amp;lt;/MortgageValueUpperBound&amp;gt;
     &amp;lt;PropertyValue&amp;gt;
     100000
     &amp;lt;/PropertyValue&amp;gt;
     &amp;lt;PropertyValueLowerBound&amp;gt;
     1
     &amp;lt;/PropertyValueLowerBound&amp;gt;
     &amp;lt;PropertyValueUpperBound&amp;gt;
     500
     &amp;lt;/PropertyValueUpperBound&amp;gt;
     &amp;lt;Adverse&amp;gt;
     false
     &amp;lt;/Adverse&amp;gt;
     &amp;lt;FirstTime&amp;gt;
     false
     &amp;lt;/FirstTime&amp;gt;
     &amp;lt;/Mortgage&amp;gt;
     &amp;lt;/ExtendedInfo&amp;gt;
     &amp;lt;Applicants&amp;gt;
     &amp;lt;Applicant1&amp;gt;
     &amp;lt;Title&amp;gt;
     Mr
     &amp;lt;/Title&amp;gt;
     &amp;lt;Forename&amp;gt;
     SampleForename
     &amp;lt;/Forename&amp;gt;
     &amp;lt;Surname&amp;gt;
     SampleSurname
     &amp;lt;/Surname&amp;gt;
     &amp;lt;DateOfBirth&amp;gt;
     1903-02-01
     &amp;lt;/DateOfBirth&amp;gt;
     &amp;lt;Smoker&amp;gt;
     false
     &amp;lt;/Smoker&amp;gt;
     &amp;lt;TelephoneNumbers&amp;gt;
     &amp;lt;TelephoneNumber&amp;gt;
     &amp;lt;Number&amp;gt;
     01244123456
     &amp;lt;/Number&amp;gt;
     &amp;lt;Type&amp;gt;
     Mobile
     &amp;lt;/Type&amp;gt;
     &amp;lt;/TelephoneNumber&amp;gt;
     &amp;lt;/TelephoneNumbers&amp;gt;
     &amp;lt;EmailAddresses&amp;gt;
     &amp;lt;EmailAddress&amp;gt;
     &amp;lt;Email&amp;gt;
     test@moneysupermarket.com
     &amp;lt;/Email&amp;gt;
     &amp;lt;Type&amp;gt;
     Business
     &amp;lt;/Type&amp;gt;
     &amp;lt;/EmailAddress&amp;gt;
     &amp;lt;/EmailAddresses&amp;gt;
     &amp;lt;Addresses&amp;gt;
     &amp;lt;Address&amp;gt;
     &amp;lt;Street&amp;gt;
     Sample Street
     &amp;lt;/Street&amp;gt;
     &amp;lt;District&amp;gt;
     Sample District
     &amp;lt;/District&amp;gt;
     &amp;lt;Town&amp;gt;
     Sample Town
     &amp;lt;/Town&amp;gt;
     &amp;lt;County&amp;gt;
     Sample County
     &amp;lt;/County&amp;gt;
     &amp;lt;Postcode&amp;gt;
     CH53UZ
     &amp;lt;/Postcode&amp;gt;
     &amp;lt;Type&amp;gt;
     Home
     &amp;lt;/Type&amp;gt;
     &amp;lt;/Address&amp;gt;
     &amp;lt;/Addresses&amp;gt;
     &amp;lt;/Applicant1&amp;gt;
     &amp;lt;/Applicants&amp;gt;
     &amp;lt;/ns0:Lead&amp;gt;
     &amp;lt;Assignment&amp;gt;
     &amp;lt;Price&amp;gt;
     20
     &amp;lt;/Price&amp;gt;
     &amp;lt;AssignmentDateTime&amp;gt;
     2010-02-01T00:00:00
     &amp;lt;/AssignmentDateTime&amp;gt;
     &amp;lt;Subscription&amp;gt;
     &amp;lt;Reference&amp;gt;
     1234
     &amp;lt;/Reference&amp;gt;
     &amp;lt;Subscriber&amp;gt;
     &amp;lt;Title&amp;gt;
     Mr
     &amp;lt;/Title&amp;gt;
     &amp;lt;Forename&amp;gt;
     SampleForename
     &amp;lt;/Forename&amp;gt;
     &amp;lt;Surname&amp;gt;
     SampleSurname
     &amp;lt;/Surname&amp;gt;
     &amp;lt;/Subscriber&amp;gt;
     &amp;lt;/Subscription&amp;gt;
     &amp;lt;Account&amp;gt;
     &amp;lt;Reference&amp;gt;
     1234
     &amp;lt;/Reference&amp;gt;
     &amp;lt;CompanyName&amp;gt;
     Sample Company
     &amp;lt;/CompanyName&amp;gt;
     &amp;lt;/Account&amp;gt;
     &amp;lt;LeadType&amp;gt;
     SampleLeadType
     &amp;lt;/LeadType&amp;gt;
     &amp;lt;TerritoryName&amp;gt;
     UNITED KINGDOM
     &amp;lt;/TerritoryName&amp;gt;
     &amp;lt;/Assignment&amp;gt;
     &amp;lt;/ns1:LeadAssigned&amp;gt;
     </ns1:LeadXml><ns1:AuthenticationUsername>dealdirectfinancial</ns1:AuthenticationUsername><ns1:AuthenticationPassword>opensesame</ns1:AuthenticationPassword></ns1:request></ns1:ConsumeLead></SOAP-ENV:Body></SOAP-ENV:Envelope>
    Response: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.paaleads.com/LeadConsumerService/"><SOAP-ENV:Body><ns1:ConsumeLeadResponse/></SOAP-ENV:Body></SOAP-ENV:Envelope>
    I cannot figure out how to build the response as a nested array that matches the wsdl. Can anyone help?
  • nickweavers
    New Member
    • Feb 2007
    • 6

    #2
    It appears that the response array should not contain the top output wsdl message element, but start with the first child element.... changing my server to the following solved my problem:

    function ConsumeLead($da ta)

    $response =
    array('ConsumeL eadResult' =>
    array(
    'LeadReceived' => 'true'
    )
    );

    return $response;
    }
    The response is now working:
    Code:
    Response: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.paaleads.com/LeadConsumerService/"><SOAP-ENV:Body><ns1:ConsumeLeadResponse><ns1:ConsumeLeadResult><ns1:LeadReceived>true</ns1:LeadReceived></ns1:ConsumeLeadResult></ns1:ConsumeLeadResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
    That only took me 4 hours to solve using the Monte Carlo problem solving technique ;)
    Last edited by Niheel; Oct 6 '10, 01:40 PM.

    Comment

    Working...