NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Custom Schema vs. Schema on-the-fly


Joined: 23 Feb 2004
Posts: 6
Location: Sarnia, ON, CANADA
Reply with quote
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!
View user's profileFind all posts by NeflyteSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
Your code should be corrected a bit:
Code:
<?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);
?>
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 23 Feb 2004
Posts: 6
Location: Sarnia, ON, CANADA
Reply with quote
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 Smile
View user's profileFind all posts by NeflyteSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
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 Smile
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 23 Feb 2004
Posts: 6
Location: Sarnia, ON, CANADA
Reply with quote
The reason being that i want my own schema file...not one thats included in my WSDL. How can i reference a schema that's embeded inside a WSDL file from somewhere else?
View user's profileFind all posts by NeflyteSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
If you need a way for processing pre-generated WSDL with your own way and take a schema in particular, you'd use XML parser like expat or libxml. NuSoap itself uses expat but for parsing envelopes, not for accessing WSDL.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 23 Feb 2004
Posts: 6
Location: Sarnia, ON, CANADA
Reply with quote
But why should i have to go that far? 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?

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?

And bearing all this in mind, are you not also telling me that the only way I can get Named Types to work with NuSOAP is to declare them on-the-fly and have NuSOAP generate the schema when it generates the WSDL? (Since using my own schema file doesn't seem to be working for anything other than standard xml types)
View user's profileFind all posts by NeflyteSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
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 ? Smile
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 23 Feb 2004
Posts: 6
Location: Sarnia, ON, CANADA
Reply with quote
I simply want an external schema file. That's it Smile I'm not asking for a critique of my reasons for wanting it, i'm asking for support of this product. Everything I've read of the W3C specs say i'm able to do it. But I can't get it to work with NuSOAP. This is the nature of my post.

Can someone help me? It would be greatly appreciated. Smile
View user's profileFind all posts by NeflyteSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
That's right, W3C proposes a lot but very few things are really done in the most products. Actually I didn't intent to critique at all, quite the opposite all I'd like to do is to get closer to understanding what you really want to get. If you only critique nusoap for missing of some features proposed by W3C, that's it.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 23 Feb 2004
Posts: 6
Location: Sarnia, ON, CANADA
Reply with quote
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 Smile
View user's profileFind all posts by NeflyteSend private message
Custom Schema vs. Schema on-the-fly
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  

  
  
 Reply to topic