views:

197

answers:

1

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/"&gt;

<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/"&gt;
<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);
} 
A: 

Try changing the following line of the wsdl:

<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/"&gt;

to the actual hostname/ip address of your dev server. E.g. if your dev server were on the local network at 192.168.0.100:

<s:schema elementFormDefault="qualified" targetNamespace="http://192.168.0.100/"&gt;

I have used your code from above on my dev server and it was causing an error until I fixed that line of the wsdl.

Genesis