logo       

Re: Problem with SOAP envelope?: msg#00092

php.nusoap.general

Subject: Re: Problem with SOAP envelope?

> NuSOAP has only limited abilities to work in the document-based
> SOAP world. As you have discovered, for example, the server is
> more-or-less forced into the RPC model, in that the incoming SOAP
> payload is parsed into parameters to pass to the function handling a
> call. Programmers who want to access the raw XML for the request
> must use the requestSOAP property of soap_server, like this

I've been beating my head against the wall all day trying to figure this
problem out and was finally able to do it. I'm relating my situation
and experiences here in hopes that it might help someone else down
the line.

In creating (and testing) the server, I set up a client script that closely
mimics the sample code on the NuSOAP page. I stuck a sample XML
document into a php variable and did the following:

$client = new soapclient(
'http://eazypro.wild.net/interactive/_WebServices/PolicyInterfaceWebService.
php' );
$result = $client->call( 'PolicyInterfaceWebService', array(
'sXMLString' => $xmlDocument ));

And when I ran this script, all was well with the world. Well, ok, with
my cubicle at any rate. After putting on the finishing touches, I sent the
relevant schemas to a third party developer that is actually going to be
the one making use of my webservice. They are using ASP and as a
result cannot utilize NuSOAP. So what they ended up doing was just
sending me the entire SOAP envelope as part of a HTTP POST. That
lead to me getting the data as such:

sXMLString=%3CSOAP-ENV%3AEnvelope+SOAP-ENV%3AencodingStyle%3D%22http%3A%2F%2
Fschemas.xmlsoap.org%2Fsoap%2Fencoding%2F%22++xmlns%3ASOAP-ENV%3D%22http%3A%
2F%2Fschemas.xmlsoap.org%2Fsoap%2Fenvelope%2F%22++xmlns%3Axsd%3D%22http%3A%2
F%2Fwww.w3.org%2F2001%2FXMLSchema%22++xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.o
rg%2F2001%2FXMLSchema-instance%22++xmlns%3ASOAP-ENC%3D%22http%3A%2F%2Fschema
s.xmlsoap.org%2Fsoap%2Fencoding%2F%22++xmlns%3Asi%3D%22http%3A%2F%2Fsoapinte
rop.org%2Fxsd%22%3E%3CSOAP-ENV%3ABody%3E%3Cns1%3APolicyInterfaceWebService+x
mlns%3Ans1%3D%22http%3A%2F%2Ftesturi.org%22%3E%3CsXMLString+xsi%3Atype%3D%22
xsd%3Astring%22%3E%0D%0A%3CIntegrusEPLLitePolicyInterface%3E%0D%0A%09%3CUser
Record%3E%0D%0A%09%09%3Cfirstname%3ETest%3C%2Ffirstname%3E%0D%0A%09%09%3Clas
tname%3EUser%3C%2Flastname%3E%0D%0A%09%09%3Ccompany%3EZed+Zed+Webservice+Tes
t+Company%3C%2Fcompany%3E%0D%0A%09%09%3Caddress1%3EAddress+1%3C%2Faddress1%3
E%0D%0A%09%09%3Caddress2%3EAddress+2%3C%2Faddress2%3E%0D%0A%09%09%3Ccity%3EC
ity%3C%2Fcity%3E%0D%0A%09%09%3Cstate%3EState%3C%2Fstate%3E%0D%0A%09%09%3Ccou
ntry%3EUnited+States%3C%2Fcountry%3E%0D%0A%09%09%3Czip%3E70433%3C%2Fzip%3E%0
D%0A%09%09%3Cphone%3E1231231234%3C%2Fphone%3E%0D%0A%09%09%3Cfax%3E1231231235
%3C%2Ffax%3E%0D%0A%09%09%3Cemail%3Echris%40wild.net%3C%2Femail%3E%0D%0A%09%0
9%3Cbilling_email%3Echris%40wild.net%3C%2Fbilling_email%3E%0D%0A%09%3C%2FUse
rRecord%3E%0D%0A%09%3Corg_structure%3ECorporation%3C%2Forg_structure%3E%0D%0
A%09%3Cnaics_number%3E444220%3C%2Fnaics_number%3E%0D%0A%09%3Cprimary_categor
y%3ERetail%3C%2Fprimary_category%3E%0D%0A%09%3Csub_category%3ENurseries%2C+G
arden+Centers%2C+and+Farm+Supply+Stores%3C%2Fsub_category%3E%0D%0A%09%3Cfull
time_employee%3E25%3C%2Ffulltime_employee%3E%0D%0A%09%3Cseasonal_employee%3E
10%3C%2Fseasonal_employee%3E%0D%0A%09%3Criskman_product%3EYes%3C%2Friskman_p
roduct%3E%0D%0A%09%3Cprevious_claims%3ENo%3C%2Fprevious_claims%3E%0D%0A%09%3
Cclaims_not_reported%3ENo%3C%2Fclaims_not_reported%3E%0D%0A%09%3Crdi_or_fpa%
3EFull+Prior+Acts%3C%2Frdi_or_fpa%3E%0D%0A%09%3Cmaterial_facts%3ENo%3C%2Fmat
erial_facts%3E%0D%0A%09%3CAttachedEndorsements%3E%0D%0A%09%09%3Cendorsement_
type%3Eadditional%3C%2Fendorsement_type%3E%0D%0A%09%09%3Cpremium%3E3.14%3C%2
Fpremium%3E%0D%0A%09%09%3Cpremium_due%3E3.14%3C%2Fpremium_due%3E%0D%0A%09%09
%3Cendorsement_body%3ETest+Additional+Premium+Endorsement%3C%2Fendorsement_b
ody%3E%0D%0A%09%3C%2FAttachedEndorsements%3E%0D%0A%09%3CAttachedEndorsements
%3E%0D%0A%09%09%3Cendorsement_type%3Etext%3C%2Fendorsement_type%3E%0D%0A%09%
09%3Cpremium%3E0%3C%2Fpremium%3E%0D%0A%09%09%3Cpremium_due%3E0%3C%2Fpremium_
due%3E%0D%0A%09%09%3Cendorsement_body%3ETest+Text+Endorsement%3C%2Fendorseme
nt_body%3E%0D%0A%09%3C%2FAttachedEndorsements%3E%0D%0A%09%3CAttachedEndorsem
ents%3E%0D%0A%09%09%3Cendorsement_type%3Eadditional%3C%2Fendorsement_type%3E
%0D%0A%09%09%3Cpremium%3E3.14%3C%2Fpremium%3E%0D%0A%09%09%3Cpremium_due%3E3.
14%3C%2Fpremium_due%3E%0D%0A%09%09%3Cendorsement_body%3ETest+Additional+Prem
ium+Endorsement%3C%2Fendorsement_body%3E%0D%0A%09%3C%2FAttachedEndorsements%
3E%0D%0A%09%3CAttachedEndorsements%3E%0D%0A%09%09%3Cendorsement_type%3Eretur
n%3C%2Fendorsement_type%3E%0D%0A%09%09%3Cpremium%3E3.14%3C%2Fpremium%3E%0D%0
A%09%09%3Cpremium_due%3E3.14%3C%2Fpremium_due%3E%0D%0A%09%09%3Cendorsement_b
ody%3ETest+Return+Premium+Endorsement%3C%2Fendorsement_body%3E%0D%0A%09%3C%2
FAttachedEndorsements%3E%0D%0A%3C%2FIntegrusEPLLitePolicyInterface%3E%3C%2Fs
XMLString%3E%3C%2Fns1%3APolicyInterfaceWebService%3E%3C%2FSOAP-ENV%3ABody%3E
%3C%2FSOAP-ENV%3AEnvelope%3E%0D%0A

(sorry for the huge data dump) which isn't how NuSOAP is expecting
it. NuSOAP just wants the envelope. First things first, I stripped out
the 'sXMLString=' and urldecoded the rest of the data. That gave me
a completely valid XML document, which included the document within
the actual body of the envelope. This turned out to be a *bad* thing.

What was happening was that, apart from the element that is the
function name and the element(s) that represented the parameters
passed to the function, any other valid XML was parsed and turned
into an array. So if your HTTP POSTed data looked like this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
<soap:Header>
<!-- security credentials -->
<s:credentials xmlns:s="urn:examples-org:security" soap:mustUnderstand="1">
<username/>
<password/>
</s:credentials>
</soap:Header>
<soap:Body>
<PolicyInterfaceWebService>
<stringParam xs:type="xs:string">
<rootNode>
<childNode1>blah</childNode1>
<childNode2>blah</childNode2>
</rootNode>
</stringParam>
</PolicyInterfaceWebService>
</soap:Body>
</soap:Envelope>

What NuSOAP did was take the data within the body, determine
the function and parameter names and use the rest of the data to
create an array that looked like this:

array( 'rootNode' => array( 'childNode1' => 'blah', 'childNode2' =>
'blah' ))

That wasn't what I wanted or needed. I had to figure out what was
different between the NuSOAP soapclient::call() and sending via
HTTP POST. It turns out that NuSOAP urlencodes the actual body
of the envelope prior to sending. Such that instead of the above, what
is actually sent looks like this:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
<soap:Header>
<!-- security credentials -->
<s:credentials xmlns:s="urn:examples-org:security" soap:mustUnderstand="1">
<username/>
<password/>
</s:credentials>
</soap:Header>
<soap:Body>
<PolicyInterfaceWebService>
<stringParam xs:type="xs:string">
&lt;rootNode&gt;
&lt;childNode1>blah</childNode1&gt;
&lt;childNode2>blah</childNode2&gt;
&lt;/rootNode&gt;
</stringParam>
</PolicyInterfaceWebService>
</soap:Body>
</soap:Envelope>

So that the only valid XML is the SOAP envelope. And once
NuSOAP strips all of that away, the body is decoded again and
passed to the relevant function as XML.
Again, there are a whole lot more steps in between than I make
it seem and I'm just breaking it down to the simplest terms.

So if you want the data serialized into an array for use in your
function, make sure the body of the envelope is XML as well
when you send the envelope via HTTP POST. If you want the
data to be passed into your function as XML, make sure the
body of the envelope is urlencoded.

I hope this is of help to someone in the future.

Chris




-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise