Database operations using Silverlight 2.0 WCF and LINQ to SQL - Developing a Silverlight 2.0 page to demonstrate CRUD functionality: Explanation
(Page 5 of 5 )
This section explains the code given in the previous section.
The constructor in UI class is as follows:
Public Sub New()
InitializeComponent()
InitiateContext()
InitiateHandlers()
End Sub
“InitiateContext” and “InitiateHandlers” are custom methods developed especially to ease our process. The “InitiateContext” method instantiates a WCF Service client object (objService) along with a business object (objEmp). Once the instantiatiations are completed, the business object (objEmp) is assigned to the “DataContext” property of the “LayourRoot” container control to enable “Two-Way” data binding (explained in detail in my previous article).
Every WCF method from Silverlight UI is accessed asynchronously. Once the method at the WCF Service gets processed, the call back mechanism gets back to the method in Silverlight UI and then executes it. For call back mechanisms to work, we should register the handlers. This is handled in “InitiateHandlers.”
Every operation (a WCF method, for example) gets executed at the WCF Service in an asynchronous fashion. The following are the statements which access the WCF methods asynchronously:
objService.AddAsync(objEmp)
objService.DeleteAsync(objEmp.Empno)
objService.UpdateAsync(objEmp)
objService.GetEmployeeAsync(objEmp.Empno)
You can also observe that the same business object (objEmp) is passed while calling the respective WCF method.
In my upcoming articles, we will see more and more examples of Silverlight 2.0 development together with LINQ to SQL and WCF. I hope you enjoyed the article and any suggestions, bugs, errors, enhancements etc. are highly appreciated at http://jagchat.spaces.live.com
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |