Forum Moderators: coopster

Message Too Old, No Replies

Problem with FedEx rate request via nusoap

SOAP nusoap FedEx RateRequest

         

cameraman

2:46 am on Oct 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My shared host doesn't have SOAP installed, so I've been trying to use nusoap to send a rate request to FedEx.
After much frustration (all day today and a fair part of yesterday), I finally got it to work the "wrong" way but I'd really like to know how to do it the "right" way. For some reason, the fedex service absolutely insists on seing a namespace in the tags:
<q0:WebAuthenticationDetail>

Without them, absolutely everything else can be right but you receive an error about mismatched elements.
Since I know practically nothing about SOAP or wsdl's or any of it, what I finally did is modify the serializeEnvelope function in nusoap.php:
// serialize envelope
$body = preg_replace('/<([^\/])/','<q0:$1',$body);
$body = preg_replace('/<\//','</q0:',$body);

It certainly seems to me that the wsdl file should specify explicit namespaces, but I messed with it all day and did searches for everything I could think of to no avail. I also couldn't find an 'official' way of telling nusoap to do it.

Is this a nusoap shortcoming? What is the right way to do this?

A couple of hints for anyone else who tries this - some things need to be changed in the FedEx example script to make it work with nusoap. For one thing, it wasn't immediately apparent to me that you're supposed to download their wsdl file and put it on your server. Once you've done that, the soapclient constructor looks like this:

$client = new soapclient($path_to_wsdl_file,true);

They pass the parameters to the soap call with:
("getRate",array('params' => $request)

but that absolutely will not work - you get an envelope and no body. Instead, the array index has to be the name of the service:
$response = $client->call("getRate",array('RateRequest' => $request),$fedex_rate_path);

$fedex_rate_path is the target namespace in the wsdl file - I'd list it explicitly here but then they'd change it tomorrow. If you leave it blank, nusoap uses its default which doesn't work, and if you set it to '' it still doesn't work - it has to be the target namespace.

So if someone could enlighten me I'd sure appreciate knowing how to really do this - I don't like the modified nusoap.php file. I suppose I could extend the class but I'm sure there's a better more 'conformant' way to do it.

eelixduppy

9:08 pm on Oct 24, 2007 (gmt 0)



Doesn't look like anyone has run into this problem before. Have you gotten anywhere with this yet?

cameraman

10:16 pm on Oct 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, it works ok with the hack but I was hoping someone had experience with WSDL files and could say 'oh just stick this here' to cause the namespace to be added to the tags.

The hacked nusoap.php file won't cause any problems since it's not used anywhere else in the project, but I don't like using a hack when it seems likely that there's a better way to do it.