J'essaie de faire simplement fonctionner un web service sur mon serveur en local.
Mon client en local :
1 2 3 4 5
| <?php
$client = new SoapClient("server.wsdl");
$ret = $client->__call("hello",array('steph'));
print $ret;
?> |
Mon serveur en local :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| <?php
ini_set("soap.wsdl_cache_enabled", "0");
class MonWebService
{
function MonWebService()
{
}
/**
* Dis bonjour...
* @param string $qui
* @return string
*/
function hello($qui)
{
return utf8_encode("Bonjour à toi : ".$qui);
}
}
$server = new SoapServer("server.wsdl");
$server->setClass("MonWebService");
$server->handle();
print "Ce web service MonWebService contient les méthodes suivantes :<br><ul>";
$aFuncs = $server->getFunctions();
for($i=0;$i<sizeof($aFuncs);$i++)
{
print("<li>".$aFuncs[$i]."</li>");
}
print "</ul>";
?> |
WSDL en local :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| <?xml version='1.0' encoding='UTF-8'?>
<!-- WSDL file generated by Zend Studio. -->
<definitions name="server" targetNamespace="urn:server" xmlns:typens="urn:server" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="hello">
<part name="qui" type="xsd:string"/>
</message>
<message name="helloResponse">
<part name="helloReturn" type="xsd:string"/>
</message>
<portType name="MonWebServicePortType">
<operation name="hello">
<documentation>
Dis bonjour...
</documentation>
<input message="typens:hello"/>
<output message="typens:helloResponse"/>
</operation>
</portType>
<binding name="MonWebServiceBinding" type="typens:MonWebServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="hello">
<soap:operation soapAction="urn:MonWebServiceAction"/>
<input>
<soap:body namespace="urn:server" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:server" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="serverService">
<port name="MonWebServicePort" binding="typens:MonWebServiceBinding">
<soap:address location="http://localhost/ws/webservice/index.php"/>
</port>
</service>
</definitions> |
Quand j'appelle mon client, j'ai le message suivant qui me fait perdre mon latin :
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in C:\xampplite\htdocs\ws\webservice\test.php:3 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://localhos...', 'urn:MonWebServi...', 1, 0) #1 C:\xampplite\htdocs\ws\webservice\test.php(3): SoapClient->__call('hello', Array) #2 {main} thrown in C:\xampplite\htdocs\ws\webservice\test.php on line 3
Quand j'appelle directement le serveur, tout se passe bien visiblement :
" Ce web service MonWebService contient les méthodes suivantes :
* MonWebService
* hello "
Si ça parle à quelqu'un je suis preneur !!
Merci à tous
Partager