Hi all
I'm too newbie in web services so I can't figure out what the error I
made.
I have a SOAP server written in PHP:
<?php
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Pull in the NuSOAP code
//require_once('../../nusoap/lib/nusoap.php');
// Create the server instance
$server = new SoapServer('server.wsdl');
// Register the method to expose
$server->addFunction('hello');
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ?
$HTTP_RAW_POST_DATA : '';
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$server->handle();
}
else
{
$functions = $server->getFunctions();
foreach($functions as $func)
{
echo "$func<br>";
}
}
?>
The service is described by WSDL file:
<?xml version="1.0" encoding="utf-8"?>
<definitions name="HelloService"
targetNamespace="http://test-gentoo.home.local/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://test-gentoo.home.local/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
<portType name="Hello_PortType">
<operation name="hello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/
soap/http"/>
<operation name="hello">
<soap:operation soapAction="urn:examples:helloservice"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address location="http://192.168.0.102/web-services/soap/
server.php" />
</port>
</service>
</definitions>
Using wsdl.exe I have created a proxy class for this service. The
invocation of the service's method looks like this:
static void Main(string[] args)
{
Hello_Service client = new Hello_Service();
Console.WriteLine(client.hello("test"));
}
The request sent to the server looks like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/
encoding/"
xmlns:tns="http://test-gentoo.home.local/
HelloService.wsdl"
xmlns:types="http://test-gentoo.home.local/
HelloService.wsdl/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/
encoding/">
<q1:hello xmlns:q1="urn:examples:helloservice">
<firstName xsi:type="xsd:string">test</firstName>
</q1:hello>
</soap:Body>
</soap:Envelope>
.... and response looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/
envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Bad Request</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I can't understand where mistake is. I checked the request according
to SOAP specification - seems like it's correct. Did I miss anything?
Thank you in advance.
Mykhaylo.