Dear all,
I try to do a web service (server and client) on a Linux VPS (Debian 6 Squeeze). I use the PHP Version 5.3.3-7+squeeze27.
Here is my server (ws.php)
<?php
require_once "lib/nusoap.php";
class food {
public function getFood($type) {
switch ($type) {
case 'starter':
return 'Soup';
break;
case 'Main':
return 'Curry';
break;
case 'Desert':
return 'Ice Cream';
break;
default:
break;
}
}
}
$server = new soap_server();
$server->configureWSDL("foodservice", "http://www.airtechws.com/foodservice");
$server->register("food.getFood",
array("type" => "xsd:string"),
array("return" => "xsd:string"),
"http://www.www.airtechws.com/foodservice",
"http://www.www.airtechws.com/foodservice#getFood",
"rpc",
"encoded",
"Get food by type");
@$server->service($HTTP_RAW_POST_DATA);
?>
|
and here is my client (client.php)
<?php
require_once "lib/nusoap.php";
$client = new nusoap_client("food.wsdl", true);
$error = $client->getError();
if ($error) {
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$result = $client->call("food.getFood", array("type" => "Main"));
if ($client->fault) {
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
} else {
$error = $client->getError();
if ($error) {
echo "<h2>Error</h2><pre>" . $error . "</pre>";
} else {
echo "<h2>Main</h2>";
echo $result;
}
}
// show soap request and response
echo "<h2>Request</h2>";
echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
echo "<h2>Response</h2>";
echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
|
I saved the wsdl file that I generated with the server (www.airtechws.com/ws.php?wsdl)
<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.airtechws.com/foodservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.airtechws.com/foodservice">
<types>
<xsd:schema targetNamespace="http://www.airtechws.com/foodservice">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
</xsd:schema>
</types>
<message name="food.getFoodRequest">
<part name="type" type="xsd:string" />
</message>
<message name="food.getFoodResponse">
<part name="return" type="xsd:string" />
</message>
<portType name="foodservicePortType">
<operation name="food.getFood">
<documentation>Get food by type</documentation>
<input message="tns:food.getFoodRequest"/>
<output message="tns:food.getFoodResponse"/>
</operation>
</portType>
<binding name="foodserviceBinding" type="tns:foodservicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="food.getFood">
<soap:operation soapAction="http://www.airtechws.com/foodservice#getFood" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://www.airtechws.com/foodservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://www.airtechws.com/foodservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="foodservice">
<port name="foodservicePort" binding="tns:foodserviceBinding">
<soap:address location="http://www.airtechws.com/ws.php"/>
</port>
</service>
</definitions>
|
When I try to consume the Web Service with my client, I have this error message:
Error
HTTP Error: Unsupported HTTP response status 404 Not Found (soapclient->response has contents of the response)
Request
POST /ws.php HTTP/1.0
Host:
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "http://www.airtechws.com/foodservice#getFood"
Do you have an idea?
Thanks in advance for your help.
Content-Length: 571
[/quote]