Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 26th, 2009, 04:14 AM
Registered User
 
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default NuSoap to .Net Complex Types

Howdy,

I'm using NuSoap to call a php service.
Then I'm using .Net to consume the NuSoap wrapper.

I'm new to php.
I can return a string no problem, on my NuSoap registration I simply specify:
$server->register('Authenticate',
array('userName' => 'xsd:string', 'password' => 'xsd:string'),
array('return' => 'xsd:string'));

however I will need to return more than 1 value, so I will need to return a complex type, lets say an object with a string for Debtor code and a string for Session ID. Simple to do in .Net, and I assume simple in PHP too, however I'm clueless.

I'd imagine one option is to build up an xml string and return that, but it sounds like a hell of a lot of work for something so easy.

Please could somebody give me some advice or an example of returning a complex type consumable by .Net from a PHP - NuSoap Web Service?

Thanx,
 
Old September 26th, 2009, 10:28 AM
Registered User
 
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Resolved

The bits of code I was missing:

Setup Response Complex type in the wsdl
Code:
$server->wsdl->addComplexType('AuthResponseType',
	'complexType',
	'struct',
	'all',
	'',
	array(
		'DebtorCode' => array('name' => 'DebtorCode',
					'type' => 'xsd:string'),
		'SessionCode' => array('name' => 'SessionCode',
					'type' => 'xsd:string')
		)
	);
Register the function with the server
Code:
$server->register('Authenticate',
	array('userName' => 'xsd:string', 
		'password' => 'xsd:string'),
	array('return' => 'tns:AuthResponseType'),
	'MyApiWrapper',
	'MyApiWrapper#Authenticate',
	'rpc',
	'encoded',
	'Authenticates the login credentials and returns the debtor code and session id of the authenticated session');
The actual function, see the return array...
Code:
function Authenticate($userName, $password){
	$client = new SoapClient(null, array('location' => "http://blah.com/api.php", 'uri' => "http://blah.com/"));
	$AuthResponse = $client->authenticate($userName, $password);
	
	return array(
			'DebtorCode' => $AuthResponse->debtorCode,
			'SessionCode' => $AuthResponse->session);
}
Still seems like a lot of code, but it works. I got my response in .Net and all was well.





Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET bug: Error reflecting complex object with Nul peterwood .NET Web Services 0 February 7th, 2008 11:35 AM
Schema: element is choice of complex types? jkmyoung XML 3 July 18th, 2007 04:54 PM
.net and c# complex bindgrid page KarmenC SQL Server 2000 1 January 16th, 2005 04:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.