|
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);
?>
| Comments: | ||
| RE: Accessing .NET web service. | ayeesha | 08/22/08 06:19 |
| Fatal error | Fernando | 12/12/07 07:57 |
| Thanks a lot | Roshan shahare | 07/17/07 05:16 |
| Fatal error: | cyzar | 05/14/07 03:17 |
| SOAP help | Nimesh Master | 02/13/06 23:55 |
| RE: .NET and PHP SOAP interoperability | david | 02/10/06 06:06 |
| .NET and PHP SOAP interoperability | manitra | 12/09/05 05:47 |
| RE: Accessing .NET web service. | nikita | 10/15/05 09:00 |
| RE: Accessing .NET web service. | Umair Khan | 07/14/05 07:06 |
| Reg..Error i received while using Nusoap | Abirami | 06/08/05 08:10 |
| RE: Accessing .NET web service. | Mad | 02/17/05 12:41 |
| Accessing .NET web service. | Ramesh | 01/06/05 22:46 |
| Complex Object in request | Vikas | 12/31/04 01:31 |
| python server and php consumer | Friederich Marcks | 11/29/04 10:09 |
| RE: Email Option | Lucas Hrabovsky | 09/20/04 03:03 |
| Email Option | Mohammed Imdadullah | 04/05/04 01:59 |
| WSDL client correction | George Malamidis | 01/12/04 14:41 |
| 2 questions and a remark | bgb | 01/12/04 08:10 |
| typo in SOAP Server | Darren McHattie | 01/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. | ||


