Skip to content

Instantly share code, notes, and snippets.

@umidjons
Created July 2, 2013 09:12
Show Gist options
  • Save umidjons/5907857 to your computer and use it in GitHub Desktop.
Save umidjons/5907857 to your computer and use it in GitHub Desktop.
SOAP server/client example in WSDL mode
<?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();
?>
@jeffiec
Copy link

jeffiec commented Aug 8, 2024

any idea why i would be getting this error? "looks like we got no XML document"
what should the generated response look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment