|
| Custom Schema vs. Schema on-the-fly | |
Joined: 23 Feb 2004 |
Posts: 6 |
Location: Sarnia, ON, CANADA |
|
|
Posted: Sun Feb 22, 2004 10:31 am |
|
|
|
|
|
I'd like to be able to define a custom schema file that i can use with NuSOAP instead of defining all my types on-the-fly when i create the WSDL.
I'm getting close to an answer, but there are some difficulties that have arisen. I keep getting errors that the 'Account' type is not defined. The WSDL generates okay, and the request packet looks fine, but i get these error lines:
soap_server: done calling method: getEmail, received Array of typearray
soap_server: got a(n) array from method
soap_server: serializing return value
soap_server: got wsdl error: tns:Account (Account) is not a supported type.
Below are my schema, and server php files.
-- schema --
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://server/soap/schema/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<!-- define structures -->
<xs:element name="Account">
<xs:complexType>
<xs:sequence>
<xs:element name="key" type="xs:string"/>
<xs:element name="fname" type="xs:string"/>
<xs:element name="lname" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
<xs:element name="host" type="xs:string"/>
<xs:element name="domain" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
--------
-- server.php --
<?php
require('nusoap/nusoap.php');
$serv = new soap_server();
$serv->debug_flag = true;
$serv->configureWSDL('server','http://server/soap/schema/');
$serv->wsdl->schemaTargetNamespace = 'http://server/soap/schema/';
// register method
$serv->register('getEmail', array('key'=>'xsd:string'), array('return'=>'tns:Account'), 'http://server/soap/schema/');
function getEmail($regcode) {
return array('regkey'=>$regcode,'fname'=>'Alan','lname'=>'Lew','email'=>'alan@canweb.ca','host'=>'alan','domain'=>'server.com');
}
$serv->service($HTTP_RAW_POST_DATA);
?>
Note: my schema file exists in http://server/soap/schema/schema.xsd
Any help or advice would be greatly appreciated!
|
|
|
| | |
Site Admin
Joined: 13 Jul 2003 |
Posts: 8342 |
|
|
|
Posted: Mon Feb 23, 2004 3:40 am |
|
|
|
|
|
Your code should be corrected a bit:
<?php
require('nusoap/nusoap.php');
$serv = new soap_server();
$serv->debug_flag = true;
$serv->configureWSDL('server','http://server/soap/schema/');
$serv->wsdl->schemaTargetNamespace = 'http://server/soap/schema/';
$serv->wsdl->addComplexType(
'Account',
'complexType',
'struct',
'all',
'',
array(
'regkey' => array('name'=>'regkey','type'=>'string'),
'fname' => array('name'=>'fname','type'=>'string'),
'lname' => array('name'=>'lname','type'=>'string'),
'email' => array('name'=>'email','type'=>'string'),
'host' => array('name'=>'host','type'=>'string'),
'domain' => array('name'=>'domain','type'=>'string')
)
);
// register method
$serv->register('getEmail',
array('key'=>'xsd:string'),
array('return'=>'Account'), 'http://server/soap/schema/');
function getEmail($regcode) {
return array('regkey'=>$regcode,
'fname'=>'Alan',
'lname'=>'Lew',
'email'=>'alan@canweb.ca',
'host'=>'alan',
'domain'=>'server.com');
}
$serv->service($HTTP_RAW_POST_DATA);
?> |
|
|
|
| | |
Joined: 23 Feb 2004 |
Posts: 6 |
Location: Sarnia, ON, CANADA |
|
|
Posted: Mon Feb 23, 2004 2:21 pm |
|
|
|
|
|
The whole point of my post was to find a way to do that _without_ defining the types on-the-fly (i.e. addComplexType(...)) but instead using a schema file that I create.
After conversing with Dietrich, he informed me that I have to create my own WSDL file by hand in order to do what i want. I've done this and it seems to work for basic XML data types.
I've having other issues with using NuSOAP and some simpleType elements that i've created in my custom schema.
Thanks for your help, though
|
|
|
| | |
Site Admin
Joined: 13 Jul 2003 |
Posts: 8342 |
|
|
|
Posted: Mon Feb 23, 2004 3:19 pm |
|
|
|
|
|
What's the advantage of going that way ?
If you belive you'd do it, you may cache WSDL file on the server.
In this case you'll have to update it every time you change anything in arguments for published methods. It may gain little performance improvements but would lead to some inconveniences.
I'd suggest you not write your own WSDL from scratches, but take whatsoever generated by nusoap, save it, correct if necessary and provide an URL to is as a WSDL. Not a big deal
|
|
|
| | |
|
| | |
|
| | |
|
| | |
Site Admin
Joined: 13 Jul 2003 |
Posts: 8342 |
|
|
|
Posted: Tue Feb 24, 2004 6:36 am |
|
|
|
|
|
Quote: | But why should i have to go that far? |
I don't know. It was your idea...
Quote: | Shouldn't NuSOAP be complant to the W3C recommendations?
If someone trying to access my SOAP services decides not to use NuSOAP to do it, will they be able to complete their requests? Likewise, if I don't use NuSOAP and someone else does, will it
work then? |
Sure it works fine as a soap client as well as a soap server with many other soap clients and servers created in other tools.
Quote: | I'm just looking for the most compatible and compliant way to implement SOAP. The W3C recommendations say that I can reference external schema files in my WSDL, so I do. Should NuSOAP not allow this as well? |
Does it mean that you have a 3rd party schema files and need to work with them ? How are you going to implement your functionality in php in this case ? With nusoap being used as a soap server you effectively have a way to publish your methods/services written in php using soap protocol. What else do you need ?
|
|
|
| | |
Joined: 23 Feb 2004 |
Posts: 6 |
Location: Sarnia, ON, CANADA |
|
|
Posted: Tue Feb 24, 2004 12:20 pm |
|
|
|
|
|
I guess that's what i was also doing. However, i've been informed that i'll be embedding the schema in the WSDL anyways. But its good to know what NuSOAP can and can;t do.
I do have other questions now tho...i'll post them in a new thread.
Thanks again
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
All times are GMT - 5 Hours
Page 1 of 1
|
|
|
| |