-
-
Save umidjons/5907857 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?> | |
<definitions name="Organization" | |
targetNamespace="urn:Organization" | |
xmlns:tns="urn:Organization" | |
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="FilterRequest"> | |
<part name="params" type="xsd:string"/> | |
</message> | |
<message name="FilterResponse"> | |
<part name="result" type="xsd:string"/> | |
</message> | |
<message name="LoginRequest"> | |
<part name="login" type="xsd:string"/> | |
<part name="password" type="xsd:string"/> | |
</message> | |
<message name="LoginResponse"> | |
<part name="result" type="xsd:string"/> | |
</message> | |
<portType name="FilterPort"> | |
<operation name="doFilter"> | |
<input message="tns:FilterRequest"/> | |
<output message="tns:FilterResponse"/> | |
</operation> | |
<operation name="login"> | |
<input message="tns:LoginRequest"/> | |
<output message="tns:LoginResponse"/> | |
</operation> | |
</portType> | |
<binding name="FilterBinding" type="tns:FilterPort"> | |
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> | |
<operation name="doFilter"> | |
<soap:operation soapAction="urn:FilterAction"/> | |
<input> | |
<soap:body use="encoded" namespace="urn:Organization" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> | |
</input> | |
<output> | |
<soap:body use="encoded" namespace="urn:Organization" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> | |
</output> | |
</operation> | |
<operation name="login"> | |
<soap:operation soapAction="urn:LoginAction"/> | |
<input> | |
<soap:body use="encoded" namespace="urn:Organization" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> | |
</input> | |
<output> | |
<soap:body use="encoded" namespace="urn:Organization" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> | |
</output> | |
</operation> | |
</binding> | |
<service name="WSDLService"> | |
<port name="FilterPort" binding="tns:FilterBinding"> | |
<soap:address location="http://localhost/api/wsdl/orgs/soap-server.php"/> | |
</port> | |
</service> | |
</definitions> |
<? | |
$client = new SoapClient( "http://localhost/wsdls/organization.wsdl", array( 'cache_wsdl' => WSDL_CACHE_NONE ) ); | |
try { | |
$responseLogin = $client->login( 'test_user', 'test_password' ); // call login() from .wsdl | |
if($responseLogin == "success") { // if success | |
$response = $client->doFilter( $params ); // call doFilter() from .wsdl | |
?> | |
<pre><? print_r( $response ); ?></pre> | |
<? | |
} | |
} catch ( SoapFault $sf ) { | |
echo $sf->getMessage(); | |
// Full SoapFault message | |
// echo '<pre>'; | |
// var_dump( $sf ); | |
// echo '</pre>'; | |
// Analyze last request | |
// $xml = $client->__getLastRequest(); | |
// echo $xml; | |
} | |
?> |
<? | |
ini_set( "soap.wsdl_cache_enabled", 0 ); | |
ini_set( 'soap.wsdl_cache_ttl', 0 ); | |
function login( $login, $password ) | |
{ | |
return "some string"; | |
} | |
function doFilter( $params ) | |
{ | |
return "some string"; | |
} | |
$server = new SoapServer( "organization.wsdl" ); | |
$server->addFunction( "login" ); | |
$server->addFunction( "doFilter" ); | |
$server->handle(); | |
?> |
Thank you very much so simple example. This is more than many words.
Helped me to. Thanks.
I am getting an an exception error on login as "Not Found"
The var_dump gave me the below info
object(SoapFault)#2 (9) { ["message":protected]=> string(9) "Not Found" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(41) "C:\xampp\htdocs\soap-test\soap-client.php" ["line":protected]=> int(5) ["trace":"Exception":private]=> array(2) { [0]=> array(4) { ["function"]=> string(11) "__doRequest" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(5) { [0]=> string(548) " test_usertest_password " [1]=> string(46) "http://localhost/api/wsdl/orgs/soap-server.php" [2]=> string(15) "urn:LoginAction" [3]=> int(1) [4]=> int(0) } } [1]=> array(6) { ["file"]=> string(41) "C:\xampp\htdocs\soap-test\soap-client.php" ["line"]=> int(5) ["function"]=> string(6) "__call" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(5) "login" [1]=> array(2) { [0]=> string(9) "test_user" [1]=> string(13) "test_password" } } } } ["previous":"Exception":private]=> NULL ["faultstring"]=> string(9) "Not Found" ["faultcode"]=> string(4) "HTTP" }
Simple and best example for understand how a SOAP server works with wsdl. Thanks Umid.
any idea why i would be getting this error? "looks like we got no XML document"
what should the generated response look like?
Now i understood how SOAP works, its very good example