Browse DevX
Sign up for e-mail newsletters from DevX


Enhance Your Multi-tier Applications with the Windows Communication Foundation  : Page 4

By making simple modifications to XML-based WCF configuration files, you can add security, transactability, and reliability to multi-tier applications nearly instantly.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

The Application—Client Tier
The final level in your application is the client tier. In this example the client tier is a Windows Form, which uses a proxy generated by the svcutil tool to talk to the business logic tier. You can see it in action in Figure 3.

Figure 3. The Client Application: The figure shows how the running client application looks when viewing the chat data.
Note that the sender field contains the ID established when I sign into this network (called BookDev) and my personal credentials. This has all been handled for me by the ServiceModel and the proxy generated by svcutil when I specified that the service handles Windows Credentials in its Web.config (see the previous section).

This client uses the automatically generated proxy to read the back chat API, and then loads the resulting XML into a DataGridView as shown below:

// Read the Back Chat API into a DataGridView control. ChatServiceProxy chatProxy = new ChatServiceProxy(); string strBackChat = chatProxy.GetBackChat(1); System.IO.StringReader xmlRead = new System.IO.StringReader(strBackChat); DataSet tmp = new DataSet(); tmp.ReadXml(xmlRead, XmlReadMode.Auto); dataGridView1.DataSource = tmp; dataGridView1.DataMember = "chatnode"; dataGridView1.Refresh();

You can easily expand this client to add a text box so users can type something, and have it call the InsertMessage proxy method, or to keep track of the state of the database using the GetMostRecentMessageID() method.

The Windows Communication Foundation adds major value to any multi-tier application development. By implementing your layers as services, and configuring them using the System.ServiceModel configuration in their Web.config files, you can concentrate on building your software logic, rather than on implementing the underlying plumbing to support security, reliability, transactions, and all the other functionality that enterprise-class applications require. This article showed a simple application that encompasses an n-tier architecture, illustrating how you can easily empower this architecture using the WCF service model, but already you should begin to see the raw power that WCF gives you. If you are considering or already involved in building connected systems and need security, reliability, interoperability, manageability, transactions, or any of the other typical capabilities of an enterprise system, I recommend that you begin exploring this framework to see just how much time and effort you can save.

Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.
Thanks for your registration, follow us on our social networks to keep up-to-date