Soap (Simple Object Access Protocol)

Soap is really simple protocol specification, used for exchanging structured information in the implementation of web service.
It is depend on XML(Extensible Markup Language) for its message format.
To enable SOAP on windows server, open php.ini file , find “soap” & enable extension named “extension=php_soap.dll” , i mean , remove “;” before that statement, save file , restart WAMP server & you are done, SOAP is now enable , you can check in your phpinfo().
SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.

Here , i am going to describe how you can use SOAP with PHP.

Download latest nusoap.php file
Create one server file named soap_server.php


<?php
require_once("nusoap.php");
$server = new soap_server();
$server->configureWSDL("Testing WSDL ","urn:Testing WSDL ");

$server->register("gethelloworld",array("name" => "xsd:string"),array("return" => "xsd:string"),"urn:helloworld","urn:helloworld#gethelloworld");

function gethelloworld($name) {
$myname    =    "My Name Is <b>".$name . "</b>";
return $myname;
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

3. Create one client file named helloworld.php


<?php
include("nusoap.php");
$client = new soapclient("http://localhost/soap/soap_server.php?wsdl");
$result    =    $client->gethelloworld("Milap Patel");
echo "<pre>";
print_r($result);
echo "</pre>";
?>

Advertisements

18 thoughts on “Soap (Simple Object Access Protocol)

  1. Hello ,

    Any one implement nusoap in cake php. I am implementing it on cakephp it not working properly it return empty XML . Same code are working properly in Without using Cakephp.

    If any one using it in cakephp please provide the solution for it. In Cakephp i have got following error.

    error in msg parsing:
    xml was empty, didn’t parse!

    Like

  2. Hello Milap
    Nigam is here

    I face one issue for SOAP as below

    Fatal error: Uncaught SoapFault exception: [Client] Function (“gethelloworld”) is not a valid method for this service in C:\wamp\www\SOAP\client.php:4 Stack trace: #0 [internal function]: SoapClient->__call(‘gethelloworld’, Array) #1 C:\wamp\www\SOAP\client.php(4): SoapClient->gethelloworld(‘Milap Patel’) #2 {main} thrown in C:\wamp\www\SOAP\client.php on line 4

    can you please help me out for it ?

    Thanks
    Nigam Mehta

    Like

    • Hello Nigambhai,

      I resolved it.
      Just check updated code.

      Need to change the declaration of your client object. You have to pass complete path of your soap_server.php file as below.

      $client = new soapclient(“http://localhost/soap/soap_server.php?wsdl”);

      Done..!!! Let me know if its working or not…!!! 🙂

      Like

  3. I dont know if you are going to read this but I just can’t

    Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘localhost/server.php?wsdl’ : failed to load external entity

    on the client side the server seems to be working but the client is killing me!

    Like

    • Hi Omar,

      Where is server.php file? Is it at same directory level with client file? You can pass like this.
      $client = new soapclient(“localhost/soap_server.php?wsdl”);
      Let me know if you still have problem.

      Thanks

      Like

  4. Client error.
    PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘soap_server.php?wsdl’ : failed to load external entity “soap_server.php?wsdl”

    Like

    • You have to create client as shown below.

      $client = new soapclient(“http://127.0.0.1/soap_server.php?wsdl”);

      You have to give complete URL before soap_server.php?wsdl”.

      Like

  5. Really useful post,since am new to soap.i want to mention the small correction in ur code,
    $client = new soapclient(“http://127.0.0.1/soap_server.php?wsdl”);
    should be like this.hope it helps u

    Like

  6. Array
    (
    [faultcode] => SOAP-ENV:Client
    [faultactor] =>
    [faultstring] => error in msg parsing:
    xml was empty, didn’t parse!
    [detail] =>
    )

    i am gettting this error please help me solve it. i am beginning to get frustrated.

    Like

      • the server instance
        am using codeigniter framework
        function index(){
        require_once(APPPATH.’libraries/lib/nusoap’.EXT);
        // $debug = 1;
        $server=new nusoap_server;
        $server->configureWSDL(“TMS web service “,”urn:Tms webservices “);
        $server->register(“gethelloworld”,array(“name” => “xsd:string”),array(“return” => “xsd:string”),”urn:helloworld”,”urn:helloworld#gethelloworld”);
        $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ”;
        $server->service($HTTP_RAW_POST_DATA);
        }
        the client
        function test_soap(){
        require_once(APPPATH.’libraries/lib/nusoap’.EXT); //includes nusoap
        $client = new nusoap_client(“http://127.0.0.1/liveterminals/transrecord/?wsdl”);
        $result = $client->call(“gethelloworld”,array(“name”=>”alex”));
        echo “
        “;
        print_r($result);
        echo ”
        “;
        echo ‘Request’;
        echo ‘
        ‘ . htmlspecialchars($client->request, ENT_QUOTES) . ‘
        ‘;
        echo ‘Response’;
        echo ‘
        ‘ . htmlspecialchars($client->response, ENT_QUOTES) . ‘
        ‘;
        }
        so when i access the test_soap page i got something like this
        Array
        (
        [faultcode] => SOAP-ENV:Client
        [faultactor] =>
        [faultstring] => error in msg parsing:
        xml was empty, didn’t parse!
        [detail] =>
        )
        pls help me

        Like

  7. I think the client should look like this

    $client = new soapclient(“http://localhost/soap/soap_server.php?wsdl”);

    $result = $client->call(‘gethelloworld’, array(‘name’ => ‘alex’));

    Like

I like to hear from you about this !!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s