Michael Rasmussen wrote:
On Mon, 19 Jun 2006 11:52:08 +1200, Morgan Pyne wrote:
Thx. The online documentation isn't terribly clear on all this and says
several of the functions/objects (SoapVar, SoapParam) are for non-WSDL
mode only, so I hadn't tried this. However, I just tried your suggestion
but unfortunately I'm still not getting the correct object type on the
server.
I agree, the documentation could need some brush-up.
Your example below seems to be geared towards returning an object from the
server rather than passing one to it, so here is what I tried:
Actually it is for both server and client. Read more later.
- On the client, changed the method call to pass a SoapParam instead of
directly passing my object i.e.
$client = new SoapClient('http://myurl.com/wsdl' );
$a = new someObj();
$b = new SoapParam($a, 'name_of_comlexType_from_WSDL');
$client->myRemoteMethod( $b );
On the server, the 'myRemoteMethod()' is simply displaying the object type
that it is passed. It is receiving the object as a 'StdClass', instead of
a 'someObj'
Is this the corrrect approach? Do I need to do anything additionally on
the server side?
This is perfectly normal due to the fact that PHP is not a statical typed
language. Had you tried implementing the client in C++ or C# the server
would have serialized the SoapParam to a native C++ or C# class. In PHP
you have to do this yourself, Eg. you must provide a private method in the
server class which is capable of converting from a standard class to the
required class:
1)
a) $myObj = new MyObj();
b) $myObj->import(stdClass $a);
2) a) $myObj = MyObj::import(stdClass $a);
When dealing with WSDL I would recommend you to always try your WSDL in a
WSDL parser like:
1) Mono: wsdl <WSDL file>
2) C++/gsoap: wsdl2h <WSDL file>
Or perhaps have a look at this: http://jool.nl/new/
Hi Michael,
Thanks for your explanation. I guess I had overestimated what the SOAP
extension would do on my behalf to facilitate the use of classes as
parameters and return values when calling soap methods.
I can indeed write a method within my object to convert a stdclass
object back into my custom class, but this isn't really a desirable
solution for me, mainly because it means modifying my class just so it
can be passed as a parameter. I have a lot of classes which I would like
to use as SOAP parameters (some of which are generated by other tools)
so this requirement to modify them all is a bit unfortunate.
I guess one way of writing a general solution to the problem could be to
write a function which would dynamically add a method to the user class
in question and populate it from the stdclass parameter received (using
the runkit PECL extension - runkit_method_add() - and the reflection API
to iterate over the properties), thus providing an automatic
stdclass->user class converter on demand as needed.
However, it was my understanding that this was the purpose of using
classmaps with the soap extension i.e. mapping (on both ends of a SOAP
connection) from WSDL complexTypes to PHP classes.
If this is not what classmaps are supposed to be used for, can you
explain to me how they should work and when they should be used?
Thank you for your time and answers,
Morgan
--
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php