?
Solved

how to get dataset result using php

Posted on 2007-07-28
9
Medium Priority
?
6,879 Views
Last Modified: 2013-11-18
hello there,

i am trying to use a web service which is in .Net and i am using php to call those ws.Now my problem is i cannot get the result from the ws from the dataset of ws.i want to show the result in html table.please help me to acheive this.

my php code is like this
<?php
$ini = ini_set("soap.wsdl_cache_enabled", 0);
// Create the client instance
$client = new SoapClient('http://.asmx?WSDL');
// Check for an error
$CustomerID =  2;
$parameters = array('CustomerID' => $CustomerID);
print_r($parameters);
echo "<BR>";

try
   {
            $result = $client->GetShoppingCart($parameters);
   }
   catch (SoapFault $exception)
   {
          echo("<pre>");
        print_r($exception);
            echo("</pre>");
   }
   
   if (is_soap_fault($return))
   {
          trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
   }

   
   echo("<pre>");
      print_r($return);
       echo("</pre>");
      exit;

the wsdl function i am using is like this

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <GetShoppingCart xmlns="http://tempuri.org/">
            <CustomerID>2</CustomerID>
        </GetShoppingCart>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

the response i should get is like this
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <GetShoppingCartResponse xmlns="http://tempuri.org/">
            <GetShoppingCartResult>
                <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
                    <xs:element name="NewDataSet" msdata:IsDataSet="true">
                        <xs:complexType>
                            <xs:choice maxOccurs="unbounded">
                                <xs:element name="Table">
                                    <xs:complexType>
                                        <xs:sequence>
                                            <xs:element name="ID" type="xs:int" minOccurs="0"/>
                                            <xs:element name="ParentRow" type="xs:int" minOccurs="0"/>
                                            <xs:element name="Date" type="xs:dateTime" minOccurs="0"/>
                                            <xs:element name="OperatorLocationID" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="OperatorID" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="ForLocationID" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="ForOperatorID" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="CustomerLocationID" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="CustomerID" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="ProductID" type="xs:int" minOccurs="0"/>
                                            <xs:element name="ProductAccount" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="Description" type="xs:string"
                                                minOccurs="0"/>
                                            <xs:element name="Qtty" type="xs:int" minOccurs="0"/>
                                            <xs:element name="UnitPrice" type="xs:int" minOccurs="0"/>
                                            <xs:element name="TotalPrice" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="TransactionType"
                                                type="xs:unsignedByte" minOccurs="0"/>
                                            <xs:element name="PaymentType" type="xs:unsignedByte"
                                                minOccurs="0"/>
                                            <xs:element name="PaymentInfo" type="xs:string"
                                                minOccurs="0"/>
                                            <xs:element name="Info" type="xs:string" minOccurs="0"/>
                                            <xs:element name="FixPaymentType" type="xs:boolean"
                                                minOccurs="0"/>
                                            <xs:element name="Delivery_State" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="InvOperatorID" type="xs:int"
                                                minOccurs="0"/>
                                            <xs:element name="ExtraDescription" type="xs:string"
                                                minOccurs="0"/>
                                            <xs:element name="ExtraInfo" type="xs:string"
                                                minOccurs="0"/>
                                            <xs:element name="Submit_State" type="xs:unsignedByte"
                                                minOccurs="0"/>
                                            <xs:element name="Requester" type="xs:string"
                                                minOccurs="0"/>
                                        </xs:sequence>
                                    </xs:complexType>
                                </xs:element>
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:schema>
                <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
                    xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
                    <NewDataSet xmlns="">
                        <Table diffgr:id="Table1" msdata:rowOrder="0">
                            <ID>985858</ID>
                            <Date>2007-07-29T09:04:00.0000000+03:30</Date>
                            <OperatorLocationID>1</OperatorLocationID>
                            <OperatorID>3</OperatorID>
                            <ForLocationID>1</ForLocationID>
                            <ForOperatorID>3</ForOperatorID>
                            <CustomerLocationID>1</CustomerLocationID>
                            <CustomerID>2</CustomerID>
                            <ProductID>606</ProductID>
                            <ProductAccount>99010107</ProductAccount>
                            <Description>POL-H1 21887565656</Description>
                            <TotalPrice>249500</TotalPrice>
                            <TransactionType>0</TransactionType>
                            <PaymentType>0</PaymentType>
                            <PaymentInfo/>
                            <Info>Type=New;Deployment=True;TelCenter=1;Password=tretretrewtrewt;AccType=0;UserName=21887565656;targetserver=4;Queue=0;PortalSubLocationID=1</Info>
                            <FixPaymentType>false</FixPaymentType>
                            <Delivery_State>0</Delivery_State>
                            <InvOperatorID>3</InvOperatorID>
                            <Submit_State>0</Submit_State>
                            <Requester></Requester>
                        </Table>
                        <Table diffgr:id="Table2" msdata:rowOrder="1">
                            <ID>985859</ID>
                            <ParentRow>985858</ParentRow>
                            <Date>2007-07-29T09:04:00.0000000+03:30</Date>
                            <OperatorLocationID>1</OperatorLocationID>
                            <OperatorID>3</OperatorID>
                            <ForLocationID>1</ForLocationID>
                            <ForOperatorID>3</ForOperatorID>
                            <CustomerLocationID>1</CustomerLocationID>
                            <CustomerID>2</CustomerID>
                            <ProductID>606</ProductID>
                            <Description>6%
                                21887565656</Description>
                            <TotalPrice>14970</TotalPrice>
                            <TransactionType>4</TransactionType>
                            <PaymentType>0</PaymentType>
                            <PaymentInfo/>
                            <Info>Type=New</Info>
                            <FixPaymentType>false</FixPaymentType>
                            <Delivery_State>0</Delivery_State>
                            <InvOperatorID>3</InvOperatorID>
                            <Submit_State>0</Submit_State>
                            <Requester></Requester>
                        </Table>
                        <Table diffgr:id="Table3" msdata:rowOrder="2">
                            <ID>985860</ID>
                            <ParentRow>985858</ParentRow>
                            <Date>2007-07-29T09:04:00.0000000+03:30</Date>
                            <OperatorLocationID>1</OperatorLocationID>
                            <OperatorID>3</OperatorID>
                            <ForLocationID>1</ForLocationID>
                            <ForOperatorID>3</ForOperatorID>
                            <CustomerLocationID>1</CustomerLocationID>
                            <CustomerID>2</CustomerID>
                            <ProductID>606</ProductID>
                            <Description>
                                21887565656</Description>
                            <TotalPrice>31800</TotalPrice>
                            <TransactionType>3</TransactionType>
                            <PaymentType>0</PaymentType>
                            <PaymentInfo/>
                            <Info>Type=New</Info>
                            <FixPaymentType>false</FixPaymentType>
                            <Delivery_State>0</Delivery_State>
                            <InvOperatorID>3</InvOperatorID>
                            <Submit_State>0</Submit_State>
                            <Requester></Requester>
                        </Table>
                        <Table diffgr:id="Table4" msdata:rowOrder="3">
                            <ID>985861</ID>
                            <ParentRow>985858</ParentRow>
                            <Date>2007-07-29T09:04:00.0000000+03:30</Date>
                            <OperatorLocationID>1</OperatorLocationID>
                            <OperatorID>3</OperatorID>
                            <ForLocationID>1</ForLocationID>
                            <ForOperatorID>3</ForOperatorID>
                            <CustomerLocationID>1</CustomerLocationID>
                            <CustomerID>2</CustomerID>
                            <ProductID>901</ProductID>
                            <ProductAccount>990701</ProductAccount>
                            <Descripti POL-H1
                                21887565656</Description>
                            <TotalPrice>200000</TotalPrice>
                            <TransactionType>0</TransactionType>
                            <PaymentType>0</PaymentType>
                            <PaymentInfo/>
                            <Info>Type=New</Info>
                            <FixPaymentType>false</FixPaymentType>
                            <Delivery_State>0</Delivery_State>
                            <InvOperatorID>3</InvOperatorID>
                            <Submit_State>0</Submit_State>
                            <Requester></Requester>
                        </Table>
                    </NewDataSet>
                </diffgr:diffgram>
            </GetShoppingCartResult>
        </GetShoppingCartResponse>
    </soap:Body>
</soap:Envelope>
0
Comment
Question by:zolf
  • 5
  • 3
9 Comments
 
LVL 3

Expert Comment

by:theevilworm
ID: 19589746
first off, in the first part of the script you are retrieving the result in the $result variable but after the try/catch block you are using the $return variable.

Secondly, if you are not receiving the right wsdl response just pass the parameters to the request function one by one, not in an array.
in your example it would be:
$result = $client->GetShoppingCart($CustomerID);

if it would have more parameters it would be $result = $client->GetShoppingCart($param1,$param2,$param3...);
0
 

Author Comment

by:zolf
ID: 19590243

i tried what you said.but i get this from the WS
stdClass Object
(
    [schema] =>
    [any] =>
)

and this my code i changed

$CustomerID =  2;
$parameters = array('CustomerID' => $CustomerID);
print_r($parameters);
echo "<BR>";

      try
   {
            $result = $client->GetShoppingCart($CustomerID);
            $cartResult = $result->GetShoppingCartResult;
   }
   catch (SoapFault $exception)
   {
          echo("<pre>");
        print_r($exception);
            echo("</pre>");
   }
   
   if (is_soap_fault($result))
   {
          trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
   }

   
   echo("<pre>");
      //print_r($result);
       echo("</pre>");
       echo("<pre>");
       print_r($cartResult);
       echo("</pre>");
      exit;
0
 

Author Comment

by:zolf
ID: 19590254

please help.

when i use a WSDL debugger like Oxygen it displays the data correctly.as i have displayed the output in my first comment.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:theevilworm
ID: 19594172
in the last code snippet you posted $result should hold the response object not $cartResult.


debug the soap requests with php5 and see if generated xml is valid:

$client = new SoapClient('http://.asmx?WSDL',array(
    "trace"      => 1,
    "exceptions" => 0));
$CustomerID=2;
$result = $client->GetShoppingCart($CustomerID);
print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";

Also post them here please.
0
 

Author Comment

by:zolf
ID: 19597781

Request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:GetShoppingCart/></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetShoppingCartResponse xmlns="http://tempuri.org/"><GetShoppingCartResult><xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"><xs:element name="NewDataSet" msdata:IsDataSet="true"><xs:complexType><xs:choice maxOccurs="unbounded"><xs:element name="Table"><xs:complexType><xs:sequence><xs:element name="ID" type="xs:int" minOccurs="0" /><xs:element name="ParentRow" type="xs:int" minOccurs="0" /><xs:element name="Date" type="xs:dateTime" minOccurs="0" /><xs:element name="OperatorLocationID" type="xs:int" minOccurs="0" /><xs:element name="OperatorID" type="xs:int" minOccurs="0" /><xs:element name="ForLocationID" type="xs:int" minOccurs="0" /><xs:element name="ForOperatorID" type="xs:int" minOccurs="0" /><xs:element name="CustomerLocationID" type="xs:int" minOccurs="0" /><xs:element name="CustomerID" type="xs:int" minOccurs="0" /><xs:element name="ProductID" type="xs:int" minOccurs="0" /><xs:element name="ProductAccount" type="xs:int" minOccurs="0" /><xs:element name="Description" type="xs:string" minOccurs="0" /><xs:element name="Qtty" type="xs:int" minOccurs="0" /><xs:element name="UnitPrice" type="xs:int" minOccurs="0" /><xs:element name="TotalPrice" type="xs:int" minOccurs="0" /><xs:element name="TransactionType" type="xs:unsignedByte" minOccurs="0" /><xs:element name="PaymentType" type="xs:unsignedByte" minOccurs="0" /><xs:element name="PaymentInfo" type="xs:string" minOccurs="0" /><xs:element name="Info" type="xs:string" minOccurs="0" /><xs:element name="FixPaymentType" type="xs:boolean" minOccurs="0" /><xs:element name="Delivery_State" type="xs:int" minOccurs="0" /><xs:element name="InvOperatorID" type="xs:int" minOccurs="0" /><xs:element name="ExtraDescription" type="xs:string" minOccurs="0" /><xs:element name="ExtraInfo" type="xs:string" minOccurs="0" /><xs:element name="Submit_State" type="xs:unsignedByte" minOccurs="0" /><xs:element name="Requester" type="xs:string" minOccurs="0" /></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" /></GetShoppingCartResult></GetShoppingCartResponse></soap:Body></soap:Envelope>

0
 

Author Comment

by:zolf
ID: 19597885

i cannot see the customer id which has a value 2 in the request.
0
 
LVL 3

Accepted Solution

by:
theevilworm earned 1500 total points
ID: 19616575
send the parameters as array('CustomerID'=>$CustomerID) again, normally, the soap client should be able to generate the correct xml with the right parameter names based on the wsdl without specifying them as an array.
0
 

Author Comment

by:zolf
ID: 19629999
$CustomerID=2;
$Customer = array ( 'CustomerID' => $CustomerID);
$result = $client->GetShoppingCart($Customer);
print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";

exit;

OK.after i pass the customer id in array i get to see the entered value in the request.but in the response it is not returning any value.i should get the result likew i posted in my 1st comment above
Request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:GetShoppingCart><ns1:CustomerID>2</ns1:CustomerID></ns1:GetShoppingCart></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetShoppingCartResponse xmlns="http://tempuri.org/"><GetShoppingCartResult><xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"><xs:element name="NewDataSet" msdata:IsDataSet="true"><xs:complexType><xs:choice maxOccurs="unbounded"><xs:element name="Table"><xs:complexType><xs:sequence><xs:element name="ID" type="xs:int" minOccurs="0" /><xs:element name="ParentRow" type="xs:int" minOccurs="0" /><xs:element name="Date" type="xs:dateTime" minOccurs="0" /><xs:element name="OperatorLocationID" type="xs:int" minOccurs="0" /><xs:element name="OperatorID" type="xs:int" minOccurs="0" /><xs:element name="ForLocationID" type="xs:int" minOccurs="0" /><xs:element name="ForOperatorID" type="xs:int" minOccurs="0" /><xs:element name="CustomerLocationID" type="xs:int" minOccurs="0" /><xs:element name="CustomerID" type="xs:int" minOccurs="0" /><xs:element name="ProductID" type="xs:int" minOccurs="0" /><xs:element name="ProductAccount" type="xs:int" minOccurs="0" /><xs:element name="Description" type="xs:string" minOccurs="0" /><xs:element name="Qtty" type="xs:int" minOccurs="0" /><xs:element name="UnitPrice" type="xs:int" minOccurs="0" /><xs:element name="TotalPrice" type="xs:int" minOccurs="0" /><xs:element name="TransactionType" type="xs:unsignedByte" minOccurs="0" /><xs:element name="PaymentType" type="xs:unsignedByte" minOccurs="0" /><xs:element name="PaymentInfo" type="xs:string" minOccurs="0" /><xs:element name="Info" type="xs:string" minOccurs="0" /><xs:element name="FixPaymentType" type="xs:boolean" minOccurs="0" /><xs:element name="Delivery_State" type="xs:int" minOccurs="0" /><xs:element name="InvOperatorID" type="xs:int" minOccurs="0" /><xs:element name="ExtraDescription" type="xs:string" minOccurs="0" /><xs:element name="ExtraInfo" type="xs:string" minOccurs="0" /><xs:element name="Submit_State" type="xs:unsignedByte" minOccurs="0" /><xs:element name="Requester" type="xs:string" minOccurs="0" /></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" /></GetShoppingCartResult></GetShoppingCartResponse></soap:Body></soap:Envelope>

0
 
LVL 1

Expert Comment

by:gowni
ID: 25270915
Hello Zolf, Did you get the solution for this? If yes please share. I am also getting the same problem.

Thanks in advance.

Karunakar
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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