Bonjour
Je galère depuis 2 jours pour monter un service web et comprendre les principes en php
. néanmoins j'ai plus
envie de comprendre trop, je me limite au fonctionnement, la seule source fiable à propos du sujet que j'ai trouvé est
http://wiki.sos-admin.com/wiki/Servi...c_PHP5_et_SOAP
fichier wsdl
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='MxProtect'
targetNamespace='http://example.org/MxProtect'
xmlns:tns=' http://example.org/MxProtect '
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name='MxProtectQueueSpamRequest'>
<part name='From' type='xsd:string'/>
<part name='To' type='xsd:string'/>
<part name='Subject' type='xsd:string'/>
<part name='Date' type='xsd:int'/>
<part name='Message' type='xsd:string'/>
</message>
<message name='MxProtectQueueSpamResponse'>
<part name='Result' type='xsd:int'/>
</message>
<portType name='MxProtectPortType'>
<operation name='MxProtectQueueSpam'>
<input message='tns:MxProtectQueueSpamRequest'/>
<output message='tns:MxProtectQueueSpamResponse'/>
</operation>
</portType>
<binding name='MxProtectBinding' type='tns:MxProtectPortType'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='MxProtectQueueSpam'>
<soap:operation soapAction='urn:MxProtectQueueSpam'/>
<input>
<soap:body use='encoded' namespace='urn:MxProtect'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='urn:MxProtect'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name='MxProtectService'>
<port name='MxProtectPort' binding='MxProtectBinding'>
<soap:address location='http://localhost/monwebservice/MxProtect.php'/>
</port>
</service>
</definitions> |
fichier serveur
1 2 3 4 5 6 7 8 9 10 11 12
| <?php
function MxProtectQueueSpam($From, $To, $Subject, $Date, $Message)
{
// Retourne un entier (int)
return 23;
}
ini_set(soap.wsdl_cache_enabled, 0); // desactive le cache WSDL
$server = new SoapServer('MxProtect.wsdl');
$server->addFunction('MxProtectQueueSpam');
$server->handle(); |
fichier client
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?php
// Une fois que votre le dev est termine, pensez a re-activer le cache
// en supprimant ou en commantant cette ligne
ini_set("soap.wsdl_cache_enabled", "0"); // desactive le cache WSDL
$client = new SoapClient('MxProtect.wsdl');
echo $client->MxProtectQueueSpam('from@example.org',
'to@example.net',
'Example mail',
time(),
"From: from@example.org\nTo: to@example.net\nSubject: Example mail\n\nbody of my example\n\nDaviXX\n"
);
?> |
mais là j'ai pas compris une chose, le fichier client ne fait pas appel directement au serveur directement, donc est ce que c'est le fichier wsdl qui se charge d'exécuter le fichier du serveur ?
si non c'est quoi la différence entre
$client = new SoapClient("some.wsdl");
et
1 2
| $client = new SoapClient(null, array('location' => "http://localhost/soap.php",
'uri' => "http://test-uri/")); |
Merci d'avance
Partager