Link to home
Start Free TrialLog in
Avatar of abie-hadi

asked on

How to consume an webservice with complex types from php?

Dear Experts

This is part of my webmethod in c#:


            SqlCommand query = new SqlCommand();

            query.CommandText = "SELECT id,name,email FROM guys";
            query.Connection = client;

            DataSet guysdata = new DataSet("guys");

            SqlDataAdapter readadata = new SqlDataAdapter();

            readdata.SelectCommand = query;


            return guysdata;

I tried to consume it from php with no luck:

$service = new SoapClient('http://localhost/service.asmx?WSDL');

$guys= $service->guys()->guysResult;

If I try to echo $guys I'll get a "Object of class stdClass could not be converted to string". Would you please tell me how to deal with datasets coming from webservices in PHP?.
Avatar of Rose Babu
Rose Babu
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abie-hadi


Thanks! , The Print_r command works

I don't know how to pass the data as an array in c# and parse using php, Give me a hint please?
Here is the sample web service for you

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebService_CSHARP
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
		// Response Class Structure
        public class GuysDataResponse
            public string id;
            public string name;
            public string email;


        public GuysDataResponse[] GetGuysData()

	    // Update your code here and fill the guysdata dataset

            //SqlCommand query = new SqlCommand();

            //query.CommandText = "SELECT id,name,email FROM guys";
            //query.Connection = client;
            //DataSet guysdata = new DataSet("guys");

            //SqlDataAdapter readadata = new SqlDataAdapter();

            //readdata.SelectCommand = query;


            DataTable  dt = new DataTable();
            DataRow dr;
            dt = guysdata.Tables[0];
            GuysDataResponse[] gData = new GuysDataResponse[dt.Rows.Count];

            for (int i = 0; i < dt.Rows.Count; i++)
                dr = dt.Rows[i];
                gData[i] = new GuysDataResponse();

                gData[i].id = dr["id"].ToString();
                gData[i].name = dr["name"].ToString();
                gData[i].email = dr["email"].ToString();


            return gData;



Open in new window