Need help debugging a PHP 5 SOAP hello world application

Posted by WarDoGG on Stack Overflow See other posts from Stack Overflow or by WarDoGG
Published on 2010-05-05T10:04:58Z Indexed on 2010/05/05 10:08 UTC
Read the original article Hit count: 324

Filed under:
|
|
|

I've been trying to get PHP 5 SOAP extension to work after reading every tutorial there is on the web, but to no avail. This has been very frustrating and i would really appreciate it if someone could point out where i am going wrong and why.

Thanks for your help in advance, and any more details needed i'll oblige.

The WSDL is as follows :

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="test"
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:s1="http://microsoft.com/wsdl/types/"
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:import namespace="http://microsoft.com/wsdl/types/" />

<s:element name="getUser">
<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="getUserResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="getUserResult" type="tns:bookUser" />
</s:sequence>
</s:complexType>

</s:element>

<s:complexType name="bookUser">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="ID" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="GUID" type="s1:guid" />
<s:element minOccurs="0" maxOccurs="1" name="login" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="pass" type="s:string" />
</s:sequence>
</s:complexType>

</s:schema>
</wsdl:types>

<wsdl:message name="getUserSoapIn">
<wsdl:part name="parameters" element="tns:getUser" />
</wsdl:message>
<wsdl:message name="getUserSoapOut">
<wsdl:part name="parameters" element="tns:getUserResponse" />
</wsdl:message>


<wsdl:portType name="test">
<wsdl:operation name="getUser">
<wsdl:input message="tns:getUserSoapIn" />
<wsdl:output message="tns:getUserSoapOut" />
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="testBinding" type="tns:test">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getUser">
<soap:operation soapAction="http://tempuri.org/getUser" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="testService">
<wsdl:port name="testPort" binding="tns:testBinding">
<soap:address location="http://127.0.0.1/index.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

The code for the server :

<?php

function getUser($param) {

return array(
'bookUser'=>array
(
'ID'=>1,
'GUID'=>2,
'login'=>$param->username,
'pass'=>$param->password
)
);
}

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("http://127.0.0.1/1.wsdl");
$server->addFunction("getUser");

$server->handle();

?>

and the code for the client :

$client = new SoapClient("http://127.0.0.1/index.php?wsdl", array('exceptions' => 0));

try {
$arr_data = array
(
array
(
'username'=>'xyz',
'password'=>'abc'
)
);
print_r($client->__soapCall("getUser",$arr_data));
}
catch (SoapFault $result) {
print_r($result);
} 

© Stack Overflow or respective owner

Related posts about soap

Related posts about php