Larry Collette

cSharp.focus(); others.blur();

  Home  |   Contact  |   Syndication    |   Login
  3 Posts | 0 Stories | 4 Comments | 2 Trackbacks

News



Archives

Post Categories

Basic Sites

Favorite Links

My Daily Headache / dotNet 2.0 Web Services

 

I have been developing with Visual Studio 2003 for a while and I recently convinced my company to purchase a MSDN Universal Subscription, which got me my hands on Visual Studio 2005.  Granted I went to a few live events and already received a few copies of VS 2005 Beta 2, but never had the time to get around to testing, until now.

 

My current project is to build a smart client application using FW 2.0 and secured web services w/ WSE 3.0 to a PKI (Public Key Infrastructure) enabled web application using ASP.net 1.1.

 

The current snag I have gotten myself into is the use of the Web Reference in VS 2005.  I have created a Web Service and Web Method to return the data when invoked.  I have created two methods to run tests against.

 

[WebMethod]

public myData[] getMyDataObject(int UserID) {

      return ConvertDataTableToObjectArray(new Procedures().getData(UserID));

}

 

[WebMethod]

public DataTable getMyDataTable(int UserID) {

      return new Procedures().getData(UserID));

}

 

I test this web service on the localhost just to make sure the data is returned properly when Invoked.

 

Now, on my Windows Client Application, I create my form and add the web service as my reference.  I create the object and binded it to the  DataGridView control:

 

myData[] data = new myWebService.DemoData().getMyDataObject(Member.UserID);

dataGridView1.DataSource = data;

dataGridView1.Refresh();

 

Which works fine, but I needed to filter the data.  Since this application was going to be a Smart Client, there wasn’t a point to keep going back and invoking the method, so I plan on caching the data or storing it locally in an xml until the client decides to update.  The current method receives the top 100 in a parameterized stored procedure; therefore the client is receiving all their information.

 

So I run into the issue with filtering the data.  Since I received the data as an object, I was in search of a class or method of the DataGridView control to filter and show what I need the client to see.  The best method was the filter method in BindingSource class, after trying and trying, it seemed to not work and I have no clue why:

 

myData[] data = new myWebService.DemoData().getMyDataObject(Member.UserID);

BindingSource bs = new BindingSource();

bs.DataSource = data;

bs.Filter = String.Format(“ActiveDate = ‘{0}’”, SelectedActiveDate);

dataGridView1.DataSource = bs;

dataGridView1.Refresh();

 

Since this isn’t working, I tried to go back to trying the DataView, here is where I came to a problem:

 

DataView class, correct me if I am wrong, but this class allows you to customize data from a DataTable (and nothing else???)

 

So I tried invoking Method #2 in my Web Service:

 

DataTable data = new myWebService.DemoData().getMyDataTable(Member.UserID);

DataView dv = new DataView(data);

dv.RowFilter = String.Format(“ActiveDate = ‘{0}’”, SelectedActiveDate);

dataGridView1.DataSource = dv;

dataGridView1.Refresh();

 

This is where I have found out that when you reference a WebService, VS creates a Reference.map and creating a “GenericObjectDataSource” I know damn well that my “getMyDataTable()” web method is a datatable, why does VS create this custom generic data object that I cannot convert or cast to a DataTable???  The DataType name that is created is called getMyDataTableResponsegetMyDataTableResult.datasource.  Once I set my object to this type, I just set the data source to it:

 

myWebService getMyDataTableResponsegetMyDataTableResult results =

      new myWebService.DemoData().getMyDataTable(Member.UserID);

 

dataGridView1.DataSource = results;

dataGridView1.Refresh();

 

I am still without a filter and I am about to just make date filter for the stored procedure, which makes it pointless to save the data object locally, since now I have to keep recalling the database, regardless of changes.

 

I have been staring at this thing all day, perhaps I just need another set of eyes, but with being new at the changes of VS 2005 as well as being under the gun, I am clueless of what I should do next.  What do you think or see????

 

Thanks for listening!

Larry

posted on Tuesday, January 24, 2006 1:11 PM

Feedback

# re: My Daily Headache / dotNet 2.0 Web Services 1/28/2006 5:53 PM Brian
As a work-around, you could create your own set of functions to build a new datatable which will initially be populated from your webservice and then cached. Then you can filter your local datatable instead.

HTH

-Brian

# re: My Daily Headache / dotNet 2.0 Web Services 2/13/2006 9:04 AM int19h
Use DataViewManager to filter data. And to prevent untyped results, return a typed dataset or datatable from your WebService methods.

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 1 and 7 and type the answer here: