Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2007
    Location
    India
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Web Service in PHP Using NuSoap

    Dear Friends!

    I am in a great fix, I am unable to consume the most basic Web Service in Php using NuSoap.
    Perhaps I have created it properly... as I think.

    I am attaching my Php Code files as below...

    Web Service Server File : Ws_SSoap.php
    PHP Code:
    <?php
    //require_once './include/MyConfig/Config.php';
    /*
    If I use above require_once I receive these errors in Mozilla Firefox
    //Error Starts
    XML Parsing Error: not well-formed
    Location: http://127.0.0.1/phWApp/Ws_SSoap.php?wsdl
    Line Number 1, Column 2:
    
    -^
    //Error Ends
    So I used these lines instead of require_once, and now wsdl is generated properly
    */
    $oldIPath =  ini_get("include_path");
    $myIPath "D:\\ravi\php\Libs;";
    $myIPath .= "D:\php\webapps\phWApp\include\MyPhp\Classes";
    ini_set("include_path",$myIPath.";".$oldIPath);
    require_once 
    'NuSoap/nusoap.php';
     
    //Helper Arrays...
     //-----------------------------------------
     
    $rb['host']='http://127.0.0.1'//Host ie Server
     
    $rb['nameSpace']=$rb['host']."/phWApp"//NameSpace
     
    $rb['webApp']=$rb['host']."/phWApp"//Web Application
     //-----------------------------------------

    ?>
    <?php
    //Opt debugging *before* creating server instance
    $debug 0;// To disable debugging...
    $server = new soap_server();
    $wsdlName='Ws_Test';
    $server->configureWSDL($wsdlName,$rb['nameSpace']);
    $server->wsdl->schemaTargetNamespace=$rb['nameSpace'];
    // Register the method to expose
    $server->register('sayHello');
    // Define the method as a PHP function
    function sayHello($name
    {
        return 
    'Hello, ' $name;
    }
    // Use the request to (try to) invoke the service
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA '';
    $server->service($HTTP_RAW_POST_DATA);
    ?>
    And now
    Web Service Client File : Ws_CSoap.php
    PHP Code:
    <?php
    //require_once './include/MyConfig/Config.php';
    $oldIPath =  ini_get("include_path");
    $myIPath "D:\\ravi\php\Libs;";
    $myIPath .= "D:\php\webapps\phWApp\include\MyPhp\Classes";
    ini_set("include_path",$myIPath.";".$oldIPath);
    require_once 
    'NuSoap/nusoap.php';
     
    //Helper Arrays...
     //-----------------------------------------
     
    $rb['host']='http://127.0.0.1'//Host ie Server
     
    $rb['nameSpace']=$rb['host']."/phWApp"//NameSpace
     
    $rb['webApp']=$rb['host']."/phWApp"//Web Application
     //-----------------------------------------
    ?>
    <?php
    try
    {
        
    //Create the client instance
        
    $wsdlPath=$rb['webApp'].'/Ws_SSoap.php';
        
    //$wsdlPath='http://127.0.0.1/phWApp/Ws_SSoap.php?wsdl';
        //I tried both path, but no Success

        
    $client = new soapclient($wsdlPath);

        
    $err $client->getError();
        if (
    $err
        {
            
    // Display the error
            
    echo '<p><b>Constructor error: ' $err '</b></p>';
            
    // At this point, you know the call that follows will fail
        
    }

        
    // Call the SOAP method
        
    $result $client->call('sayHello', array('name' => 'Ravi'));
        
    // Check for a fault
        
    if ($client->fault
        {
            echo 
    '<p><b>Fault: ';
            
    print_r($result);
            echo 
    '</b></p>';
        } 
        else 
        {
            
    // Check for errors
            
    $err $client->getError();
            if (
    $err
            {
                
    // Display the error
                
    echo '<p><b>Error: ' $err '</b></p>';
            }
            else 
            {
                
    // Display the result
                
    print_r($result);
            }
        }
        echo 
    "<hr/>";
        
    // Display the request and response
        
    echo '<h2>Request</h2>';
        echo 
    '<pre>' htmlspecialchars($client->requestENT_QUOTES) . '</pre>';
        echo 
    "<hr/>";
        echo 
    '<h2>Response</h2>';
        echo 
    '<pre>' htmlspecialchars($client->responseENT_QUOTES) . '</pre>';
        echo 
    "<hr/>";
        
    // Display the debug messages
        
    echo '<h2>Debug</h2>';
        echo 
    '<pre>' htmlspecialchars($client->debug_strENT_QUOTES) . '</pre>';
        echo 
    "<hr/>";
    }
    catch(
    Exception $ex)
    {
          print 
    $ex->getMessage();      
    }
    ?>
    So, I have explained all things, I have done to achieve this goal...
    And if some one finds any errors or omissions, then please rectify it with proper comments including my old code,
    and post back these two files after running it without any error...

    Thanks in Advance!

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Whats your problem/error you are receiving?

  • #3
    New Coder
    Join Date
    Dec 2007
    Location
    India
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello iLLin!

    Quote Originally Posted by iLLin View Post
    Whats your problem/error you are receiving?
    Sir, did you run these files on your system?
    In theory these files are correct, as I know, but make it run at least one time, If you get success then Please give me link and version of NuSoap, you used.
    When I Access Web Service as
    PHP Code:
    $wsdlPath=$rb['webApp'].'/Ws_SSoap.php';
    $client = new soapclient($wsdlPath,false); 
    I recieve these errors :-
    [05-Jan-2008 10:43:01] PHP Warning: SoapClient::SoapClient() expects parameter 2 to be array, boolean given in D:\php\webapps\phWApp\Ws_CSoap.php on line 24
    [05-Jan-2008 10:43:01] PHP Fatal error: SoapClient::SoapClient() [<a href='function.SoapClient-SoapClient'>function.SoapClient-SoapClient</a>]: Invalid parameters in D:\php\webapps\phWApp\Ws_CSoap.php on line 24
    But When I Access Web Service as
    PHP Code:
    $wsdlPath=$rb['webApp'].'/Ws_SSoap.php';
    $client = new soapclient($wsdlPath); 
    I receive these errors :-
    [05-Jan-2008 11:00:30] PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://127.0.0.1/phWApp/Ws_SSoap.php' in D:\php\webapps\phWApp\Ws_CSoap.php on line 27

    If still you are unable to get some info about my problem then please run these file on your system and check result whether it is ok or not?

    And I am using
    Apache HTTP v2.0
    PHP v5.2.1
    MySQL v5.0.45-Community-NT
    OS 4 Development :Windows XP Professional v2002,SP2
    OS 4 Hosting : Linux-Fedora
    NoSoap v0.6.5

    Thanks a Lot!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •