Foren-Übersicht php Soap Beispiel

php Soap Beispiel

Beitrag 18.11.2008 16:33
elexis_linux Site Admin

Beiträge: 396
Website: http://ModernHosting.ch
Als erstes muss man soap im apache konfigurieren (installieren). Dies werde ich jetzt aber nicht behandeln.

client.php:

Code: Alles auswählen

<?php $client = new SoapClient( 'quotes.wsdl' ); try { echo $client->getQuote( 'twain' ); } catch ( SoapFault $exception ){ echo $exception->faultstring; } ?>
quotes.wsdl:

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>
server.php:

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(); ?>

4 poziom opinie

Zurück zu „php soap“



Wer ist online?

Mitglieder in diesem Forum: Bot und 0 Gäste