In this tip, I continue the series on using Web services and Datasets. In the first tip, I explained how to create a Web Service that retrieves data from a stored procedure into a Dataset and transmits it in its XML representation to the consuming application.
In the second tip, I explained how to consume the Web service, and explained how the XML representation gets transformed back into a Dataset. I used that Dataset by DataBinding it to a DataGrid for display in an ASP.NET Web Form.
In this tip, I demonstrate how to make changes to the data in the Dataset (on the client application), then send the modified Dataset back to the Web service provider to update the database. To accomplish this, Microsoft has created the concept of a DiffGram. Due to the disconnected nature of the Dataset, it is possible that many different sources (other applications, or many different users of the same application) could have changed the underlying data after it was sent to our consumer. Also, its possible that our consuming application can do more than just update the data...perhaps it can add new rows of data to the Dataset, or delete rows of data from the Dataset. The Dataset keeps a running log of all changes to the original dataset to know 1) what happened, and 2) when did it happen. Then, when the dataset is passed back into the Web service, the dataset can be reconciled back into the original data source. Updates to the dataset will result in update statements to the data source. Inserts that occurred on the client to the dataset will result in insert statements to the original data source. The same is true for deletes, as well. The key is that the DataAdapter knows how to reconcile inserts, updates and deletes back to the data source and map the appropriate fields, parameters, etc. I use the terms "the DataAdapter knows" accomodatively -- it doesn't just "know." You must tell it, but the way you do this is through the DataAdapter Wizard, as I'll demonstra
To continue reading for free, register below or login
To read more you must become a member of SearchSOA.com
');
// -->

te in just a moment.
To illustrate this, I've created a new Web service and a new Client application that retrieves an Affiliate's information, allows the user to change it in a Web Form, then return the updated information back to the Web service server where the data source is updated with the changes. I've provided the source code, and I've provided a screen cam video that walks through the entire creation process. These tools should be used in conjunction with this tip to get the complete picture of what is going on. In the rest of this article, I'll outline the steps at a high level that were used to accomplish this.
Compile both the Web service and the Web Form. Then run the Web Form application and watch the magic happen. This is a great model for how Web services and Dataset were designed to operate. You can expand this model to do as much processing on the client (consumer) as possible, then when you are finished upload the changes back to the Web service data provider and allow it to rectify the changes back into the database. You can even be clever about how you save information back, alerting the user that the underlying data has changed and asking them if they are sure they want to overwrite these changes. Try adding this level of functionality in your applications before .NET -- especially considering how few lines of code we actually wrote!
I hope you enjoy these tips, and stay tuned for the next one where I will show the exact structure of the DiffGram and the DataSet that is being passed back and forth between the consumer and provider through the use of SOAP Extensions.
About the Author
[IMAGE]Robert Tabor is a Microsoft Certified Professional in Visual Basic with over six years of experience developing n-tier Microsoft-centric applications for some of the world's most prestigious companies and consulting organizations, such as Ernst & Young, KPMG, Cambridge Technology Partners, Sprint, American Heart Association, and the Mary Kay Corporation. Bob is the author of Microsoft .NET XML Web services by Sams Publishing, and contributes to
SoapWebservices.com and LearnVisualStudio.NET. He is currently working on initiatives within Mary Kay, the second largest eCommerce site in retail volume on the net, of how to utilize .NET within their e-business group.