Please help with SoapClient for Freight Module

Posts: 73
Joined: 12/16/2007
Uber Donor

I am trying to create a module to calculate freight charges. The freight service that I need to use used SOAP. This is pretty new to me but I have looked through the FedEx contrib module and researched online.

I seem to be unable to create the SoapClient though. Here is the current code I am using:

<?php
$client
= new SoapClient("https://services.echo.com/Quote.asmx?wsdl");
?>

The quote module hangs with the line in place / just an infinite animated graphic and the text 'receiving quotes'. I take the line out and my functions continue. I have verified with my host that soap is enabled I have copied the wsdl file to my server and renamed it ...wsdl, I have tried using other confirmed wsdl files. I always get the same result.

Any ideas why this is hanging here, or how I should implement the SoapClient??? Please help!

Posts: 73
Joined: 12/16/2007
Uber Donor
Posts: 971
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

That line works for me, and if I deliberately misspell the wsdl URL it give me a failure message - it doesn't just hang.

You should verify for yourself that SOAP support was built into your PHP install - run phpinfo() and make sure of this, don't just take the word of your web host provider. SOAP is not built into PHP by default, and many hosts (especially low-cost ones) will refuse to add it, or will be unaware that it isn't enabled.

Also, try http instead of https - is your PHP built --with-openssl (needed for https)?

When you copied the wsdl to your server, are you sure the argument of the SoapClient constructor pointed to the right place on your local filesystem?

I find that the easiest way to develop these web services is to first write a standalone script that makes the request and gets the response. Only after you have that working should you try to put it into the Ubercart framework - otherwise it will be difficult to pinpoint where the error lies.

--

<tr>.

Posts: 73
Joined: 12/16/2007
Uber Donor

TR, thanks for you response. I was able to get the client object made with wsdl but for the life of me I can't figure out how to get the proper request sent to the server. The documentation that the company gave me is very slim.

I can make a client connection:

<?php
$client
= new SoapClient(something.wsdl);
?>

but any request I form and send to the server results in an exception being thrown:

<?php
$response
= $client ->__soapCall("GetQuote", array('parameters' => $request));
?>

Error msg:

Fault

Code:soap:Server
String:Server was unable to process request. ---> Object reference not set to an instance of an object.

Any ideas on how I need to form the $request and send it to the server? I have looked through tons of online docs and forums and tried many variations, but at best I get the above error.

Posts: 971
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

Sounds like you're getting through to the server - just need to make sure the request is well-formed. The wsdl contains a complete description of the schema. You need to build an associative array with the correct keys and the correct datatypes. It's case sensitive. Read the wsdl and make sure you have all the required elements in the request array. It's dull reading, but if you can follow along what I did in the FedEx module that should help. In particular, see the code I use to print out the request (function print_request_response), and use that to compare what you're sending with whatever example you have or with the wsdl.

--

<tr>.

Posts: 73
Joined: 12/16/2007
Uber Donor

I have spent an a lot of time trying to get a response, with no luck. Perhaps you can give me a little more help?

I found an implemented a test script at: http://thecosmicgift.com/test.php . It lists all of the available methods and list the types needed to use those methods. [ The methods will be listed as ReturnStuct methodName(RequestStruct $requestVariable) ] and then shows the generated soap request envelope and response.

The array is output above the envelopes. If I send the array like this:

<?php
$data
= $client ->__soapCall("GetQuote", array('parameters' => $request));
?>

There is no parameters sent in the envelope. If I try it like this:

<?php
$data
= $client ->__soapCall("GetQuote",$request);
?>

The data is sent (although not properly formed). But in either case it throws an exception as mentioned above:

soap:Server
Server was unable to process request. ---> Object reference not set to an instance of an object.

I just don't know how else to try this. I guess the problem is in the way that I am building the array but I can't figure out the proper way to build it and send it.

I really appreciate the help you've given me so far. If you could possible look at that test input and offer any more help I would greatly appreciate it.

Thanks~