Solved

PHP SOAP pass form array to WSDL on remote server

Posted on 2007-03-20
1
1,768 Views
Last Modified: 2013-11-18
Dear Experts.

I am stuck on a small problem with PHP5 Soap / WSDL.

I need to pass the contents of a form to fill a WSDL on another server. This needs to be sent as an array.

The array is sent as a $param and I have attemted to do it like this:

$weborder = array('OrderID'=>$OrderID,'UserName'=>$UserName,'Password'=>$Password,'CusID'=>$DealerID,'SiteID'=>$DealSiteID,'Title'=>$title,'CusFname'=>$fname,'CusLName'=>$lname, 'BillAddr1'=>$addr1,  'BillAddr2'=>$addr2, 'BillAddr3'=>$addr3, 'BillAddr4'=>$addr4, 'BillPCode'=>$postc, 'BillPhone'=>$phone, 'BillMobile'=>$mobile,  'BillEmail'=>$email);

$param["WebsiteOrder"] = $Weborder;


$client = new SoapClient("http://www.somewhere.com/service.asmx?WSDL");
$RIOresult = $client -> ReadInOrder($param);

And my hope was that it would populate this WSDL correctly

 <ReadInOrder xmlns="http://www.somewhere.com/">
    <OrderID>$OrderID</OrderID>
      <UserName>$UserName</UserName>
      <Password>$Password</Password>
      <WebsiteOrder>
        <CusID>$DealerID</CusID>
        <SiteID>$DealSiteID</SiteID>
        <Title>$title</Title>
        <CusFName>$fname</CusFName>
        <CusLName>$lname</CusLName>
        <BillAddr1>$addr1</BillAddr1>
        <BillAddr2>$addr2</BillAddr2>
        <BillAddr3>$addr3</BillAddr3>
        <BillAddr4>$addr4</BillAddr4>
        <BillPCode>$postc</BillPCode>
        <BillPhone>$phone</BillPhone>
        <BillMobile>$mobile</BillMobile>
        <BillEmail>$email</BillEmail>

 </WebsiteOrder>
    </ReadInOrder>

But the best I can get is this error

Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\Inetpub\wwwroot........etc

Can anyone help me decifer the problem and set me on the path to enlightenment!

many thanx


0
Comment
Question by:imagicstudios
1 Comment
 
LVL 1

Accepted Solution

by:
cubical10 earned 500 total points
Comment Utility
Build a test file to display how php is parsing the wsdl.
Instantiate the SoapClient with the option array('trace' => 1), this will enable some debug options.
<?
$server = 'http://someserver/path/to/wsdl.wsdl';
$client = new SoapClient($server, array('trace' => 1));

echo '<h4>Available Methods</h4>';

$methods = $client->__getFunctions();
echo "<ol>\n";
foreach ($methods as $k => $method) {
            echo "<li>$method</li>";
}
echo "</ol>\n";

echo "<h4>Supported Types</h4>";
$types = $client->__getTypes();
echo "<ol style=\"white-space: pre;\">\n";
foreach ($types as $k => $type) {
            echo "<li>$type</li>";
}
echo "</ol>\n";

?>
This file will now list all of the available methods and list the types needed to use those methods.
The methods will be listed as ReturnStuct methodName(RequestStruct $requestVariable).

You will have to connect the dots so to speak.  As usually the RequestStruct is made up of other structs.  If you share the output of the file above, i can help you some more.

You can add the following code to above file to view the generated soap request envelope and response.

$parameters = //array or object or string or whatever...
print_r($parameters);
      try {
            $data = $client->methodName($parameters);
            print_r($data);
            
      } catch (SoapFault $soapFault) {
            echo $soapFault;
      }
      $request = $client->__getLastRequest();
      $request = str_replace('><',">\n<",$request);
      echo "<hr><textarea rows='20' cols='250' style='background-color: #dddddd; color: blue;'>$request</textarea>";
      $response = $client->__getLastResponse();
      $response = str_replace('><',">\n<",$response);
      echo "<hr><textarea rows='20' cols='250' style='background-color: #eeeeee; color: purple;'>$response</textarea>";
}

As a final note, if the RequestStruct is of an Abstract type, then you are going to need to build your request parameter with SOAPVar: http://us2.php.net/manual/en/function.soap-soapvar-construct.php

Hope this helps...

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now