5 Replies - 2765 Views - Last Post: 06 January 2009 - 03:57 PM Rate Topic: -----

#1 sultan_tipu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-January 09

Data From Web Service

Post icon  Posted 05 January 2009 - 05:55 PM

Hi All

How I can display data in a gridview from a webservice.
Is This A Good Question/Topic? 0
  • +

Replies To: Data From Web Service

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Data From Web Service

Posted 05 January 2009 - 07:21 PM

A web service returns XML, so I would begin by looking for ways to bind XML to a GridView.

The following link will get you started.

Binding to XML Data in ASP.NET 2.0
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Data From Web Service

Posted 06 January 2009 - 07:06 AM

View PostJayman, on 5 Jan, 2009 - 09:21 PM, said:

A web service returns XML, so I would begin by looking for ways to bind XML to a GridView.

The following link will get you started.

Binding to XML Data in ASP.NET 2.0


Not necessarily. It really depends on what data is being passed back from the webservice. If he consumes the web service in VS, then he doesn't need to deal with the XML. He only needs to deal with the data that is being sent back. If it is returning a List<string>, then he just needs to deal with that data and doesn't need to deal with the XML.
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Data From Web Service

Posted 06 January 2009 - 10:07 AM

I would disagree with your statement. A web service returns XML, it doesn't matter what the data type the method returns.

To give you an example, the following implements a generic list which is returned from the web method.

Web Service:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
	public Service () {

		//Uncomment the following line if using designed components 
		//InitializeComponent(); 
	}


	[WebMethod]
	public List<Test> Test1()
	{
		List<Test> test = new List<Test>();
		Test ts = new Test();
		ts.Prop1 = "Cool";

		test.Add(ts);

		return test;

	}

	public class Test
	{
		private string prop1 = "Test1";
		public Test()
		{ }

		public string Prop1
		{
			get { return prop1; }
			set { prop1 = value; }
		}
	}
}



When the method is invoked here is the data that is returned from the web method. If that is not XML, then I don't know what is.
  <?xml version="1.0" encoding="utf-8" ?> 
- <ArrayOfTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
- <Test>
  <Prop1>Cool</Prop1> 
  </Test>
  </ArrayOfTest>


It really doesn't matter whether the data is consumed in VS or not. The data returned will be XML, the only difference is VS will handle a lot of the work automatically.

If you have an example that shows otherwise, I would be happy to see it.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Data From Web Service

Posted 06 January 2009 - 01:40 PM

View PostJayman, on 6 Jan, 2009 - 12:07 PM, said:

I would disagree with your statement. A web service returns XML, it doesn't matter what the data type the method returns.

To give you an example, the following implements a generic list which is returned from the web method.

Web Service:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
	public Service () {

		//Uncomment the following line if using designed components 
		//InitializeComponent(); 
	}


	[WebMethod]
	public List<Test> Test1()
	{
		List<Test> test = new List<Test>();
		Test ts = new Test();
		ts.Prop1 = "Cool";

		test.Add(ts);

		return test;

	}

	public class Test
	{
		private string prop1 = "Test1";
		public Test()
		{ }

		public string Prop1
		{
			get { return prop1; }
			set { prop1 = value; }
		}
	}
}



When the method is invoked here is the data that is returned from the web method. If that is not XML, then I don't know what is.
  <?xml version="1.0" encoding="utf-8" ?> 
- <ArrayOfTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
- <Test>
  <Prop1>Cool</Prop1> 
  </Test>
  </ArrayOfTest>


It really doesn't matter whether the data is consumed in VS or not. The data returned will be XML, the only difference is VS will handle a lot of the work automatically.

If you have an example that shows otherwise, I would be happy to see it.


I have almost the exact same web method in a web service running on my home PC. It returns a generic string list. I call it, and it returns a generic list, and I go on processing that list. I never touch the XML. I do not have any code handling the XML data. I use the data that is return from the method, just like I would any other method from a separate class. Whether that is VS/.Net handling it behind the scenes for me, I don't really care. I just know that I do absolutely nothing to handle the XML data. I simply use the returned object like I would a returned object from any other method.

So for the OP, there is no reason for him to try to figure out how to bind the XML data to a DataGrid. Just return an object that is bindable to a GridView and that's all he needs.

If you would like to see my code, I can post it once I get home.

This post has been edited by eclipsed4utoo: 06 January 2009 - 01:41 PM

Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Data From Web Service

Posted 06 January 2009 - 03:57 PM

I never said you had to touch the XML, I simply stated that a web service returns XML. I also never indicated that the OP had to do anything specific with the XML data, other than binding it to the GridView.

Since he asked a very generic question, I gave him the generic answer that will certainly always apply. In addition, he did not provide any specifics on what the web service was returning. Perhaps he has no control over the web service, but instead can only consume it. Well, in that case, your solution will never work.

The reason the code I posted and the code you have works is the object is serialized. Meaning it can be converted into a sequence of bits that can be sent over a network, ie. XML. While this will work for some objects it will not work for all complex objects, at least not without some modification.

Anyway, I digress. FYI, here are some links that will provide you and the OP with a better understanding of how a web service works should you want to know more.

Web Services explained
Returning objects from web services
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1