|
|
 |
| 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

September 26th, 2009, 05:14 AM
|
|
Registered User
|
|
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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,
|

September 26th, 2009, 11:28 AM
|
|
Registered User
|
|
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |