How to consume an webservice with complex types from php?

abie-hadi used Ask the Experts™
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?.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Team Manager
can you try print_r($guys) ? check what displayed in webpage as well as in viewsource.

and instead returning the dataset, why dont you retun the array of values and parse the data in php?
if you return the array of values like below, then it will be very easy to parse in php.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
    <GetGuysDataResponse xmlns="">

Open in new window


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?
Rose BabuSenior Team Manager

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial