client.php:
Code: Alles auswählen
<?php
$client = new SoapClient( 'quotes.wsdl' );
try {
echo $client->getQuote( 'twain' );
}
catch ( SoapFault $exception ){
echo $exception->faultstring;
}
?>
Code: Alles auswählen
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='Quotes'
targetNamespace='http://example.org/Quotes'
xmlns:tns=' http://example.org/Quotes '
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='getQuoteRequest'>
<part name='author' type='xsd:string'/>
</message>
<message name='getQuoteResponse'>
<part name='Result' type='xsd:string'/>
</message>
<portType name='QuotesPortType'>
<operation name='getQuote'>
<input message='tns:getQuoteRequest'/>
<output message='tns:getQuoteResponse'/>
</operation>
</portType>
<binding name='QuotesBinding' type='tns:QuotesPortType'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='getQuote'>
<soap:operation soapAction='urn:xmethods-delayed-quotes#getQuote'/>
<input>
<soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name='QuotesService'>
<port name='QuotesPort' binding='QuotesBinding'>
<soap:address location='http://localhost/soap/server.php'/>
</port>
</service>
</definitions>
Code: Alles auswählen
<?php
class SoapQuotes {
public $quotes = array(
'twain' => 'Wer was wo.'
);
public function getQuote( $author ) {
if( isset( $this->quotes[$author] ) ) {
return $this->quotes[$author];
}
else {
throw new SoapFault( 'Server' , 'Unbekannter Author '.$author );
}
}
}
ini_set( 'soap.wsdl_cache_enabled' , '0' ); // disabling WSDL cache
$server = new SoapServer( 'quotes.wsdl' );
$server->setClass( 'SoapQuotes' );
$server->handle();
?>