Está en la página 1de 3

PHP NuSOAP Tutorial =================== http://www.codeproject.

com/Articles/140189/PHP-NuSOAP-Tutorial

Hello, World! Example Web Service ================================= require_once("nuSOAP/lib/nusoap.php"); $server = new soap_server(); //Create a new soap server $namespace = "http://localhost/nusoaphelloworld/index.php"; //Define our namespa ce $server->wsdl->schemaTargetNamespace = $namespace; $server->configureWSDL("HelloWorld"); //Configure our WSDL $server->register('HelloWorld'); // Register our method function HelloWorld() { return "Hello, World!"; } // Get our posted data if the service is being consumed , otherwise leave this d ata blank. $POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DAT A'] : ''; $server->service($POST_DATA); // pass our posted data (or nothing) to the soap service exit(); -------------------------------------------------------------------------------Less Trivial Example ==================== require_once("nuSOAP/lib/nusoap.php"); $namespace = "http://localhost/nusoaphelloworld/index.php"; $server = new soap_server(); // create a new soap server $server->configureWSDL("HelloExample"); // configure our WSDL $server->wsdl->schemaTargetNamespace = $namespace; // set our namespace $server->register( //Register a method that has parameters and return types 'HelloWorld', // method name array('name'=>'xsd:string'), // parameter list array('return'=>'xsd:string'), // return value(s) $namespace, // namespace false, // soapaction: (use default) 'rpc', // style: rpc or document 'encoded', // use: encoded or literal 'Simple Hello World Method'); // description: documentation for the method //Create a complex type $server->wsdl->addComplexType('MyComplexType','complexType','struct','all','', array( 'ID' => array('name' => 'ID','type' => 'xsd:int'), 'YourName' => array('name' => 'YourName','type' => 'xsd:string')));

$server->register( //Register our method using the complex type 'HelloComplexWorld', // method name array('name'=>'tns:MyComplexType'), // parameter list array('return'=>'tns:MyComplexType'), // return value(s) $namespace, // namespace false, // soapaction: (use default) 'rpc', // style: rpc or document 'encoded', // use: encoded or literal 'Complex Hello World Method'); // description: documentation for the method function HelloWorld($name) { return "Hello " . $name; } //Our Simple method

function HelloComplexWorld($mycomplextype) { //Our complex method return $mycomplextype; } // Get our posted data if the service is being consumed // otherwise leave this data blank. $POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DAT A'] : ''; $server->service($POST_DATA); // pass our posted data (or nothing) to the soap service exit(); -------------------------------------------------------------------------------Complex Types ============= //Create a complex type $server->wsdl->addComplexType('MyComplexType','complexType','struct','all','', array( 'ID' => array('name' => 'ID','type' => 'xsd:int'), 'YourName' => array('name' => 'YourName','type' => 'xsd:string'))); $server->register( //Register our method using the complex type 'HelloComplexWorld', // method name array('name'=>'tns:MyComplexType'), // parameter list array('return'=>'tns:MyComplexType'), // return value(s) $namespace, // namespace false, // soapaction: (use default) 'rpc', // style: rpc or document 'encoded', // use: encoded or literal 'Complex Hello World Method'); // description: documentation for the method --------------------------------------------------------------------------------

Consumption C# ============== http://www.jpreece.com/tutorials/php/developing-soap-web-services-with-php-cshar p/ http://www.codeproject.com/Articles/84345/Developing-SOAP-Web-Services-with-PHPC Note: This tutorial uses Visual C# 2010, but also uses .NET Framework 2.0.

var ex = new HelloExample(); string simpleResult = ex.HelloWorld("Jon"); var myComplexType = new MyComplexType {ID = 1, YourName = "Jon"}; MyComplexType complexResult = ex.HelloComplexWorld(myComplexType); //Output Console.WriteLine("Simple: {0}", simpleResult); Console.WriteLine("Complex: {0}", complexResult.YourName); textBox1.Text = simpleResult; textBox2.Text = complexResult.YourName; -------------------------------------------------------------------------------################################################################################ Programming with NuSOAP Programming with NuSOAP Part 2 ============================== http://www.scottnichol.com/nusoapprog.htm http://www.scottnichol.com/nusoapprog2.htm

Web Services with PHP & nuSoap Part 1.1 ========================================= http://shallop.com/2011/09/webservices_tutorial_part_1/