开发者

Returning a Dataview in a WCF Service

I have a method in my web service which returns a DataView,

开发者_StackOverflow中文版

I have setup a proxy which talks to this service but when i make this method in the proxy

public DataView GetSales(DateTime SalesDate)
{
    ServiceClient client = new ServiceClient();
    return client.GetSalesForDay(SalesDate);             
}

I get the error "Cannot implicitly convert type 'object[]' to 'System.Data.DataView', i have tried googling this but not getting anywhere, any help would be much appreciated.

Thanks


You can't do this - you cannot and should not return something like a DataView from a WCF service ever. A WCF service would only ever return data - not objects with behavior (DataView contains a lot of behavior - sorting, filtering, etc.).

Instead, in your service code, do this:

  • query your database with a SqlDataReader
  • parse out the relevant info you really need (only those fields you're really interested in) into DTO's (Data Transfer Objects) - basically just plain objects holding nothing but the properties of a "sale" that are important to you
  • return a List from your WCF service

Instead of doing steps 1 and 2 yourself, you could also use Linq-to-SQL, NHibernate, or any other capable ORM to handle that conversion from row/columns in the database to an object for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜