I'm new in the field of web service. I'm using c# for creating the web service and php for using the service. It's working fine when i'm passing simple string messages however when i'm returning the datatable the generated xml is bit complex and when i'm calling them from php it generates a odd output which i don't understand how to make array from that. The codes i have used are the followings:
c# code for Web Service
[WebMethod]
public DataSet Get_SAC(string k)
{
DataTable dt = Get("select * from SACMaster", "SacMaster");
DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds;
}
NOTE:The function Get(string Query,string TableName) is used for executing the query and fetching the data from database and setting the name of the datatable.
The XML i got from this method
<DataSet xmlns="http://tempuri.org/">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="SacMaster">
<xs:complexType>
<xs:sequence>
<xs:element name="slno" type="xs:int" minOccurs="0"/>
<xs:element name="serviceName" type="xs:string" minOccurs="0"/>
<xs:element name="sacNo" 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="">
<SacMaster diffgr:id="SacMaster1" msdata:rowOrder="0">
<slno>1</slno>
<serviceName>HOUSEKEEPING/PANTRY BOY</serviceName>
<sacNo>998533</sacNo>
</SacMaster>
<SacMaster diffgr:id="SacMaster2" msdata:rowOrder="1">
<slno>2</slno>
<serviceName>SECURITY GUARD</serviceName>
<sacNo>998525</sacNo>
</SacMaster>
<SacMaster diffgr:id="SacMaster3" msdata:rowOrder="2">
<slno>3</slno>
<serviceName>Other Employment</serviceName>
<sacNo>998519</sacNo>
</SacMaster>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
The PHP code for using the Webs Service
<?php
$client = new SoapClient("http://localhost:49439/Service1.asmx?WSDL");
$params1 = array( 'k' => '202');
$result2 = $client->Get_SAC($params1)->Get_SACResult;
print_r($result2);
?>
The Output of PHP Code
stdClass Object ( [schema] => [any] => 1HOUSEKEEPING/PANTRY BOY9985332SECURITY GUARD9985253Other Employment998519 )
Now the problem of mine is how can i convert this output into an array and if there is a problem with the generation of XML file how can i solve the problem.
The result i want is
slno |Description |Code
----------------------------------------
1 |HOUSEKEEPING/PANTRY BOY |998533
2 |SECURITY GUARD |998525
3 |Other Employment |998519