<Merry Christmas ⁄>
<mySnippets order="rand" ⁄>
<myBlog show="last" ⁄>
<myNews show="rand" ⁄>
<myNews type="cat" ⁄>
<myPhoto order="random" ⁄>
<myAdSense ⁄>
<myQuote order="random" ⁄>
<myContacts ⁄><email ⁄>
<windows live messenger ⁄>
<myCurriculum type="pdf" ⁄>
<myVisitorsMap ⁄>
<?php include_once ("nusoap.php"); $namespace = "http://localhost/webservice/"; $webservice = new soap_server(); $webservice->configureWSDL('MyWebService',$namespace); //configurar o objecto WSDL $webservice->wsdl->schemaTargetNamespace = $namespace; //registar um método $webservice->register( 'ws_StringReverse', //nome da função array('str'=>'xsd:string'), //o que recebe array('str_reversed'=>'xsd:string'), //o que devolve $namespace, "$namespace#ws_StringReverse", 'rpc', 'encoded', 'Reverte uma string'//descrição ); //registar outro método $webservice->register( 'ws_StringLength', //nome da função array('str' => 'xsd:string'), //o que recebe array('str_length' => 'xsd:int'), //o que devolve $namespace, "$namespace#ws_StringLength", 'rpc', 'encoded', 'Obter o tamanho de uma string'//descrição ); /** * Webservice que reverte uma string * * nota: sim é básico e pointless, mas o objectivo era mesmo * mostrar um exemplo do webservice :) * * @param String $str * @return String */ function ws_StringReverse($str){ $str_reversed=strrev($str); return new soapval('return','xsd:string',$str_reversed); } /** * Webservice que reverte uma string * * nota: sim é outra função básica e pointless, mas o objectivo era mesmo * mostrar um exemplo do webservice :) * * @param String $str * @return String */ function ws_StringLength($str){ $str_length=strlen($str); return new soapval('return','xsd:string',$str_length); } //processa o pedido e devolve a resposta $webservice->service($HTTP_RAW_POST_DATA); ?>
<?xml version="1.0" encoding="ISO-8859-1"?> <definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://localhost/webservice/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://localhost/webservice/"> <types> <xsd:schema targetNamespace="http://localhost/webservice/"> <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/> </xsd:schema> </types> <message name="ws_StringReverseRequest"><part name="str" type="xsd:string"/></message> <message name="ws_StringReverseResponse"><part name="str_reversed" type="xsd:string"/></message> <message name="ws_StringLengthRequest"><part name="str" type="xsd:string"/></message> <message name="ws_StringLengthResponse"><part name="str_length" type="xsd:int"/></message> <portType name="MyWebServicePortType"> <operation name="ws_StringReverse"> <documentation>Reverte uma string</documentation> <input message="tns:ws_StringReverseRequest"/> <output message="tns:ws_StringReverseResponse"/> </operation><operation name="ws_StringLength"> <documentation>Obter o tamanho de uma string</documentation> <input message="tns:ws_StringLengthRequest"/> <output message="tns:ws_StringLengthResponse"/> </operation> </portType> <binding name="MyWebServiceBinding" type="tns:MyWebServicePortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="ws_StringReverse"> <soap:operation soapAction="http://localhost/webservice/#ws_StringReverse" style="rpc"/> <input> <soap:body use="encoded" namespace="http://localhost/webservice/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap:body use="encoded" namespace="http://localhost/webservice/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> <operation name="ws_StringLength"> <soap:operation soapAction="http://localhost/webservice/#ws_StringLength" style="rpc"/> <input> <soap:body use="encoded" namespace="http://localhost/webservice/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap:body use="encoded" namespace="http://localhost/webservice/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> <service name="MyWebService"> <port name="MyWebServicePort" binding="tns:MyWebServiceBinding"> <soap:address location="http://localhost/webservice/WebService.php"/> </port> </service> </definitions>
<?php include_once ('nusoap.php'); $wsdl = "http://localhost/webservice/WebService.php?wsdl"; $str="Este é o meu WebService!"; //testar ws_StringReverse $clientStringReverse = new soapclient($wsdl,'wsdl'); $param = array('str'=>$str); echo "ws_ReverseString: $str <=> ".$clientStringReverse->call('ws_StringReverse',$param); #vai imprimir: ws_ReverseString: Este é o meu WebService! <=> !ecivreSbeW uem o é etsE echo "<hr>"; //testar ws_StringLength $clientStringLength = new soapclient($wsdl,'wsdl'); $param = array('str'=>$str); echo "ws_StringLength: $str <=> ".$clientStringLength->call('ws_StringLength',$param); #vai imprimir: ws_StringLength: Este é o meu WebService! <=> 24 ?>