phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Web Services: How PHP Kiss VB.NET? (Part 1)

Tag: web services, NuSoap   Category: PHP Classes
post: 16 Nov 2007 read: 7,255


XML, SOAP, and multitier programming is amazing technology that make we can collaborate with other programmer building big size and complex application in multiplatforms. This technology make us more easy and more simple in complicated world.

This tutorial about connecting PHP with VB.NET using web services. Why I use VB.NET to explain web services in PHP? I just want to show one of function of web services, connecting multiplatform.

In php, we can use nusoap library to create web services. You can download this library at http://sourceforge.net/projects/nusoap/. In this tutorial use nusoap-0.7.3.

  1. Download nusoap library.
  2. Extract to web directory, example within C:\AppServ\www\test. Rename folder became "nusoap". So, you get structure like this:
  3. Now, we will create server function. Create "server.php" within C:\AppServ\www\test\nusoap. Enter following code:
    
    <?
    //call library
    require_once ('lib/nusoap.php');
    
    //using soap_server to create server object
    $server = new soap_server;
    
    //register a function that works on server
    $server->register('hello');
    
    // create the function
    function hello($name)
    {
      if(!$name){
        return new soap_fault('Client','','Put your name!');
      }
    	
      $result = "Hello, ".$name;
      return $result;
    }
    
    // create HTTP listener
    $server->service($HTTP_RAW_POST_DATA);
    
    exit();
    ?>
    
  4. Now, it is time to test. Point your browser to http://localhost/test/nusoap/server.php. If work, you will get like following screen:
  5. After create server, now we will test this server function. Create "client.php" at test/nusoap. Enter following code:
    
    <?
    require_once ('lib/nusoap.php');
    
    //Give it value at parameter
    $param = array( 'name' => 'Babablackship');
    
    //Create object that referer a web services
    $client = new soapclient('http://localhost:8048/test/nusoap/server.php');
    
    //Call a function at server and send parameters too
    $response = $client->call('hello',$param);
    
    //Process result
    if($client->fault)
    {
      echo "FAULT: <p>Code: (".$client->faultcode."</p>";
      echo "String: ".$client->faultstring;
    }
    else
    {
      echo $response;
    }
    ?>
    

Now, point your browser to http://localhost/test/nusoap/client.php. You should see:

You can change value of parameter at line 5. But if value is nothing, it raise error message. Next tutorial, we will try to read the web services from VB.NET. Don't miss it!


Series this article:
Web Services: How PHP Kiss VB.NET? (Part 1)
Web Services: How PHP Kiss VB.NET? (Part 2)
PHP - Web Services: Serving Data Array
PHP - Web Services: Fetching Data From Database

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting