views:

294

answers:

3

Hiya,

I've been thrown a project which I have to say I've not got the faintest idea where to start so I'm hoping someone can give me some pointers here!

I'm working with a SharePoint intranet, and I need to query a web service which has been set up. In the words of the guy who set it up:

  1. The result of that query will be a DataSet (.Net framework)
  2. Dataset will consist of 1 DataTable
  3. Datatable will have 3 columns: Name, Department and link
  4. Name and Department are to be displayed in a GridView and the link field as underlying PostbackUrl property for the Name field.
  5. Just above the Grid a heading
  6. Set the EmptyDataText property to: “No Records”

Now I've worked with SQL and PHP, AJAX etc and so on, but I've not had to use .net or anything so I'm really not sure how you

a) Go about querying this Dataset b) In what format it sends back data

If I can crack those 2 questions I'm pretty happy I can format the result and make it look pretty. My best guess is that it sends back an XML feed with the columns he talks of as elements in the XML?

Cheers!

A: 

You do not really query datasets in the way you would query a database because they are objects with collections of objects.

Rather you would iterate through collections of objects pulling out what you want and then casting this output into an appropriate data type. 'for each' loops are one option.

the first google link for 'ado.net datatable' .... http://msdn.microsoft.com/en-us/magazine/cc163709.aspx

has what you need about half way down. Obviously you don't care about the ado.net connection parts.

This code fragment is maybe more useful - shorter and shows the iteration clearly.

http://www.eggheadcafe.com/articles/20030903.asp

Alternativley,

given the languages you are listing, you may want to ask for a more universal data format ... such as XML as you suggest .... this would be a more language independent format to use.

Its easy to publish a new web service method that will return the same dataset as an xml document in a string format ... simply use the to xml method of the dataset, pipe that into an Xdocument and .toString() it ...

John Nicholas
OK, that makes sense, and by the looks of it the webservice does indeed return XML, but my major query is first and foremost:How the hell do I query the webservice and see what it's sending back?If I can just get a response from it I should be able to format the response.
hfidgen
i've not looked at how a dataset gets formatted as its sent ... asmx webservices tend to transmit everything in XML (you can change this with a few options). the objects being sent are serialised into this. If you use .Net on the other end it will automatically deserialise the objects back into datasets for you. Maybe you can work with the XMl from here - I have never tried but don't see why not.
John Nicholas
A: 

For a debugging tool that helps you test the web service and see what is returned, have a look at STORM. There is also a WCF version if you're using a WCF service.

I've found this tool invaluable for seeing what a web service is doing. The only issue I've had is that it can be a little picky - your web service has to conform to standards or else it will barf.

Alex Angas
+1  A: 

If you are using Visual Studio, you should be able to create a quick little web app you can use to test connecting to the web service. If the web service has a published location, you can just add a new web reference to your project and put in the URL to the ASMX you are connecting to.

To do this:

  1. Right-click on your Web project
  2. Select "Add Web Reference"
  3. Enter the URL for your web service you are connecting to, and find the web service definition you want.
  4. Name the reference
  5. Press the "Add Reference" button.

You can now reference this web reference in your code using the name you gave it in step 4.

MyWebServiceName ws = new MyWebServiceName();
ws.WebServiceMethodName(query);

This should at least help you get started with getting the information from the webservice.

Jay S