471,350 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Creation a simpliest web service

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.

Jun 2 '07 #1
0 1510

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Will Arrowsmith | last post: by
14 posts views Thread by Bert Vandenberghe | last post: by
8 posts views Thread by Ankit Aneja | last post: by
1 post views Thread by Enrico Foschi | last post: by
3 posts views Thread by Limunski Magarac | last post: by
1 post views Thread by mitrofun63 | last post: by
2 posts views Thread by =?Utf-8?B?am9obnByZW1p?= | last post: by
reply views Thread by =?Utf-8?B?U2ViYXN0aWFuIEZyw6Ruaw==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.