0

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
Dwipraj Dutta
  • 83
  • 1
  • 6
  • Possible duplicate of [How do I convert an object to an array?](https://stackoverflow.com/questions/2476876/how-do-i-convert-an-object-to-an-array) – IsThisJavascript Feb 05 '18 at 11:09
  • The output you have is an object; as the duplicate says, use [get_object_vars](http://php.net/manual/en/function.get-object-vars.php) – IsThisJavascript Feb 05 '18 at 11:10
  • You can see the outputs are different because there is no separator in my output and get_object_vars(object) is not working. – Dwipraj Dutta Feb 05 '18 at 11:19
  • Sorry it appears I may have mistaken your question. You may want to update your question on how to parse the XML. `get_object_vars()` should convert `$result2` into an array but what you are asking is splitting the key `any` into an array. Which is a much complex matter. – IsThisJavascript Feb 05 '18 at 11:26
  • You could try constructing with a white space character, may I suggest using [MONGOLIAN VOWEL SEPARATOR](https://www.fileformat.info/info/unicode/char/180e/index.htm) and that way you will have something to split against. – IsThisJavascript Feb 05 '18 at 11:28

0 Answers0