tags:

views:

309

answers:

3

I am working on WCF with DataSet.xsd in a C# application.

Could you please tell me how to do Update and Delete?

A: 

Your question is very unclear and broad - I don't think anyone can really give you an answer.

As far as I understand, you are using the .NET DataSet to store and manipulate data. And you want to somehow use updates and deletes using a WCF service.

The problem here is: the DataSet mechanism really isn't designed to work in a service oriented world. The DataSet approach is designed for an application having direct access to its data source - whether that be SQL Server, or Access, or whatever. It works by loading the data talking directly to the database, and is more or less a one-to-one "in-memory" database replica.

WCF on the other hand is service-oriented - and you typically work with single object and / or lists or collections of objects - not DataSets.

Typically, a WCF service might look something like:

[ServiceContract]
interface ICustomerService
{
    [OperationContract]
    Customer LoadCustomerByID(int customerID);

    [OperationContract]
    List<Customer> LoadCustomersByCountry(string country);

    [OperationContract]
    int SaveCustomer(Customer customer);

    [OperationContract]
    int DeleteCustomer(int customerID);
}

You're typically not using DataSets and WCF together - they don't match very well. DataSets carry a pretty significant overhead with them, which doesn't work well in a service world.

If you must continue using DataSets, and want to use a WCF service to update and delete your objects, you could

  • create a WCF service something like above to update or delete an entity

  • when saving your DataSet, determine those entities that need to be updated by calling YourDataSet.GetChanges(DataRowState.Modified) and then call the UpdateEntity method on your WCF service for each of those rows

  • determine those entities that need to be deleted by calling YourDataSet.GetChanges(DataRowState.Deleted) and then call the DeleteEntity method on your WCF service for each of those rows

With this approach, you could continue to use your DataSet in your app, and still use a WCF service to update and delete your objects.

marc_s
A: 

While I agree with marc_s, we've been using datasets with our WCF services without issue. When you generate your service proxy, the dataset defined on the WCF service will be available on the client through the exposed types in the proxy class. The WCF service will have an update method where it takes a dataset as a parameter, and within that method you'll call .AcceptChanges(). Mark that service method as <OperationContract(IsOneWay:=False)>. This will allow you to pass the updated/saved dataset back to the client either as a return type or a ByRef parameter.

Jacob Ewald
A: 

Relevant blog post

I worked through this link in some detail today. It provides a fair amount of detail with respect to passing datasets from WCF and providing update functionality, although I don't think the update capability is fully coded.

EricF