Page 1 of 1
How to response one object type in webservices?
Posted: Thu Jul 19, 2007 1:46 am
by andrewknight
I defined one function to display object in server.php, such as adodb_page()
Now, I need to display this object in client.php
I tried to modify the response type to 'object' in wsdl file,but failed
any idea about this?
thanks in advance
Posted: Thu Jul 19, 2007 4:55 am
by feyd
andrewknight wrote:any idea about this?
No. Why? Lack of information.
code like below
Posted: Thu Jul 19, 2007 5:18 am
by andrewknight
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[size=150][b]server.php like shown below[/b][/size]
Code: Select all
<?php
include_once ('include/adodb/adodb.inc.php');
include_once('include/adodb/adodb-pager.inc.php');
function getTemp($paraid) {
$conn
$strsql="select * where table where id=".$paraid;
$pager = new ADODB_Pager($conn,$strsql);
$pager->Render($rows_per_page=2);
$conn->Close();
return $pager;
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("test.wsdl");
$server->addFunction("getTemp");
$server->handle();
?>
Portion code of test.wsdl
Code: Select all
<message name='getTempRequest'>
<part name='symbol' type='xsd:string'/>
</message>
<message name='getTempResponse'>
<part name='Result' type='[color=red]xsd:object'[/color]/>
</message>
<portType name='TempPortType'>
<operation name='getTemp'>
<input message='tns:getTempRequest'/>
<output message='tns:getTempResponse'/>
</operation>
</portType>
below is client.php
Code: Select all
<?php
$paraid = $_GET['paraid'];
$client = new SoapClient("test.wsdl");
$return = $client->getTemp($paraid);
echo($return);
?>
any advice? thanks
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Jul 19, 2007 9:48 am
by Begby
Well for one thing you your getTemp() object never returns anything. Your SOAP functions should never echo anything, but only return stuff.
I would start simple. Make a function that returns a string like 'hello world'. Then a client that retrieves that value and displays it. After you get that working, then start working towards getting your function to return an object. Make small changes then test it after each change to see what happens.
Using a WSDL generator will help a lot. There is one built into Zend Studio that helps immensely and generates the WSDL complete with return values based on phpdoc blocks. I am sure that other generators exist out there as well.
In order to return an object you will need to have a classmap for that object on the client side and the class declared on that side as well I believe. Check out php.net for examples.