logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: General Query: msg#00118

Subject: Re: General Query
Hi,

Scott, the difficulty arises when knowing when to use an instance of a PHP object, what properties to in that method, when to use XML, when to use objects, integers, strings and the likes... to take a service (that wsdl2php helped us with, consider the following...

<?php

class GetQuote
{
var $quote;
}
class quote
{
var $any;
}
class performquoteservice extends SoapClient
{
function __construct($wsdl, $options)
{
parent::__construct($wsdl, $options);
}
}

// Create Instance of GetQuote
$objGetQuote = new GetQuote();

// Create an Instance of quote for the GetQuote object
$objQuote = new quote();

// Load XML String into $objQuote
$objQuote->any = $strXMLFromFile; // see sample.xml attached

// Load quote into GetQuote
$objGetQuote->quote = $objQuote;

// Run GetQuote through quoteserver
$result = $objClient->GetQuote($objGetQuote);
// Output
header('Content-type: text/plain');
print_r($result);

?>

.. the resulting XML is correct...

...beacuse it's sending two objects, the properties of which are another object... and then a string of XML (which is incidentally the result of a DOMDocument::saveXML() call..)

Oddly, this works fine - I assume the method call knows how to correctly serialize them to XML - annoyingly, the SoapClient::__getLastRequest() output is semantically *identicle*, but not syntactically as when we used any of 5/6/7 different methods of formulating the request.

On the other hand, that service for which I attached the screen-shot of parameters works fine, with the DOMDocument's xml-string output passed through new SoapVar(...string..., XSD_ANYXML)... but that may just be different implementations of web services.

In the end, one assumes that with XML being just text.. surely any semantically equivillant string would suffice!

Lee H 

On 18 Apr 2007, at 18:09, Scott Nichol wrote:

Your use of str_replace with XSD_XMLANY may fix the problem I had heard of previously.

I am curious: what constitutues "complex services"?  Is it services with dozens of methods that force you to peruse lots of WSDL?  Services that use many complexTypes?  Many issues have come across this mailing list, but they tend to be very specific, such as "here's a sample of the SOAP request I need to produce, how do I do it?"  Those inquiries create a certain picture of the types of tutorials that are most useful.  You seem to present a different need, and I'd like to understand it better to possibly address it for everyone.

Scott Nichol

----- Original Message ----- From: "Lee Hambley" <lee@xxxxxxxxxxxxxx>
Cc: "Scott Nichol" <snicholnews@xxxxxxxxxxxxxxx>; "alex cropper" <alex.cropper@xxxxxxxxx>
Sent: Wednesday, April 18, 2007 12:38 PM
Subject: Re: [Nusoap-general] General Query



On 18 Apr 2007, at 16:45, Scott Nichol wrote:

We're building the request using the DomDocument object and then,
usually using a combination of SoapVar and one of it's constant
(second) arguments .. usually XSD_ANYXML - we're struggling so much
with pure trial and error!

This is a method that will typically get you tantalizingly close to
the right SOAP payload, but almost never totally correct.

It's a shame, that DOMDocument isn't 100% correct - it's a brilliant
method for mocking up what essentially is an XML document! I've
managed to use it correctly to hook into an insurance companies site,
with code like this:

$___name_removed___->getSoapWorker()->PerformQuote(new SoapVar
(str_replace('<?xml version="1.0" encoding="UTF-8">', '', $dom-
>saveXML()), XSD_ANYXML));

Where the $___name_removed___ is a generic class, and getSoapWorker()
returns an instance of PHP's built in SoapClient - the str_replace is
to strip the XML declaration from the resulting output of $dom, which
is - as you may imagine an instance of PHP's DOMDocument.

PerformQuote() is a method from the WSDL - which when examined
reveals that it expects the following:




--------------------------------------------------------------------------------



(sorry to attach an image, it saved on typing!)

Using the DOMDocument to spec out an XML file, where the root node is
called 'PerformQuoteRequest' (the same you will note, as the WDSL
generated method) the above method seems to work, although - I'm
currently facing server-side XSD errors, but I know that's because
one of my node trees is malformed.


How did you learn to use SOAP with PHP correctly, and how would you
advise we learn the same ?

Because I came to NuSOAP with lots of SOAP experience, my learning
curve was mainly mapping my knowledge to NuSOAP's design.  It
sounds like you are probably learning SOAP and a PHP implementation
at the same time, which is much harder.  Some tutorials would
probably help you a lot. The ones I did for NuSOAP are,
unfortunately, old enough that I am not sure they work any more.
That says good things about how much NuSOAP has evolved, but does
not help you much.

I did look at the nuSoap tutorials on your site, they - like a lot of
the information online didn't seem advanced enough for the kind of
complex services we were accessing! Having said that though, we just
purchased a copy of "Pro PHP XML and Web Services" - and that doesn't
go much further!


The primary problem arises knowing what 'type' to send a request as -
using __getTypes() on the client is reporting a variety of complex
types (we're working on clients for ~6 web services) - conventional
wisdom says that SOAP is just XML, and XML is just text.. so we can
send a string - bt we're not getting very far with that approach!

There are a couple of ways to attack this, assuming the services
supply WSDL.  One is to get a tool like wsdl2php (http://
www.urdalen.no/wsdl2php/).  I have not used it, but it has been
mentioned on this list.  I believe it will create a PHP proxy for
you to use that (hopefully) will make types easier.  A second way
to go is to learn to read the WSDL well enough (it won't take long)
to determine the right complexTypes to use.  In NuSOAP, you then
just create an associative array with keys corresponding to the
type elements.  An example complexType would be

We just tried briefly with wsdl2php - thanks for the heads up on that
- it generates a class that extends SoapClient, and is good enough to
generate some generic classes with properties that mirror those
expected by the web service; it makes sure you use the correct types
by enforcing the types of your arguments:

public function somewdslgeneratedmethod(CustomTypeClass $parameter)
{
// etc
// ... this code here calls the wsdl method, using the $parameter
you have sent, and of course it knows it is of the correct type to
serialize.
}


<xsd:complexType name="SOAPStruct">
<xsd:all>
<xsd:element name="varString" type="xsd:string" minOccurs="1"
maxOccurs="1"/>
<xsd:element name="varInt" type="xsd:int" minOccurs="1"
maxOccurs="1"/>
<xsd:element name="varFloat" type="xsd:float" minOccurs="1"
maxOccurs="1"/>
</xsd:all>
</xsd:complexType>

Your PHP to create a variable of this type would be

$struct = array('varString' => 'who', 'varInt' => 2, 'varFloat' =>
3.14159);

That seems pretty straightforward to me.

Scott Nichol


Cheers - the rest of our week doesn't seem too bleak now!

Lee Hambley




--------------------------------------------------------------------------------


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.


--------------------------------------------------------------------------------


_______________________________________________
Nusoap-general mailing list


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Nusoap-general mailing list
Nusoap-general@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/nusoap-general

Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>