Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Building Web Services Using NuSOAP Toolkit
SOAP Server
Our server is going to create the web service. We will register one method (getWeather) which will accept a string (city) and return an array with degrees measurement and weather forecast.
First we need NuSOAP toolkit (nusoap.php), which we'll be in our "inc" directory so that we can easily include it. So let's look at the actually needed code:

<?php
    
/**************************************************************
    *  Description:
    *  Creates a simple SOAP Server (server.php).
    **************************************************************/
        
    // includes nusoap classes
    
require('inc/nusoap.php');
   
    
// create server
    
$l_oServer = new soap_server();
  
    
// wsdl generation
    
$l_oServer->debug_flag=false;
    
$l_oServer->configureWSDL('Weather', 'http://weather.org/Weather');
    
$l_oServer->wsdl->schemaTargetNamespace = 'http://weather.org/Weather';

    
// add complex type
    
$l_oServer->wsdl->addComplexType(
        
'WeatherData',
        
'complexType',
        
'struct',
        
'all',
        
'',
        array(
            
'degrees' => array('name'=>'degrees', 'type'=>'xsd:string'),
            
'forecast' => array('name'=>'forecast', 'type'=>'xsd:string'))
    );
  
    
// register method
    
$l_oServer->register('getWeather', array(
        
'city' => 'xsd:string'),
            array(
'return'=>'tns:WeatherData'),
                
'http://weather.org/Weather');
  
    
// method code (get DB result)
    
function getWeather ($a_stInput) {
        if (
is_string($a_stInput)) {   
            
$l_oDBlink   = @mysql_connect(
                
'localhost', 'someone', 'something');
            
$l_oDBresult = @mysql_db_query(
                
'weather',
                
'SELECT degrees, forecast FROM current_data WHERE city = LCASE("' . mysql_escape_string((string)$a_stInput) . '") LIMIT 1');
          
            
// simple error checking
            
if (!$l_oDBresult) {
                return new
soap_fault('Server', '', 'Internal server error.');
            }
    
            
// no data avaible for x city
            
if (!mysql_num_rows($l_oDBresult)) {
                return new
soap_fault('Server', '',
                    
'Service contains data only for a few cities.');
            }
            
mysql_close($l_oDBlink);
          
            
// return data
            
return mysql_fetch_array($l_oDBresult, MYSQL_ASSOC);    
        }
        
// we accept only a string
        
else {
          return new
soap_fault('Client', '', 'Service requires a string parameter.');
        }
      }
  
    
// pass incoming (posted) data
    
$l_oServer->service($HTTP_RAW_POST_DATA);
?>
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
RE: Accessing .NET web service.ayeesha08/22/08 06:19
Fatal errorFernando12/12/07 07:57
Thanks a lotRoshan shahare07/17/07 05:16
Fatal error:cyzar05/14/07 03:17
SOAP helpNimesh Master02/13/06 23:55
RE: .NET and PHP SOAP interoperabilitydavid02/10/06 06:06
.NET and PHP SOAP interoperabilitymanitra12/09/05 05:47
RE: Accessing .NET web service.nikita10/15/05 09:00
RE: Accessing .NET web service.Umair Khan07/14/05 07:06
Reg..Error i received while using NusoapAbirami06/08/05 08:10
RE: Accessing .NET web service.Mad02/17/05 12:41
Accessing .NET web service.Ramesh01/06/05 22:46
Complex Object in requestVikas12/31/04 01:31
python server and php consumerFriederich Marcks11/29/04 10:09
RE: Email OptionLucas Hrabovsky09/20/04 03:03
Email OptionMohammed Imdadullah04/05/04 01:59
WSDL client correctionGeorge Malamidis01/12/04 14:41
2 questions and a remarkbgb01/12/04 08:10
typo in SOAP ServerDarren McHattie01/10/04 07:02
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.