Developing a WCF Service Library and Hosting it as WCF Web Service Using VS2K8 - Testing the WCF Web Service: creating the WCF Client using Windows Forms
(Page 5 of 5 )
To test the WCF web service created in previous sections, we need to develop a WCF client. In this case, for simplicity, I would like to work with Windows Forms.
Open a new Visual Studio environment, create a new project, select "Windows Forms Application" as the template, provide the name "WCFSampleClient" and hit OK (fig 13).

Figure 13
Design a form which looks like the following (fig 14):

Figure 14
Add a reference to WCF Service by right clicking on project and selecting "Add Service Reference" (fig 15).

Figure 15
Provide the previously created WCF Web Service URL as http://iisservername/WCFSampleService/EmpService.svc?wsdl and click "Go." Once it is found, designate the namespace as "EmpService" and hit OK (fig 16).

Figure 16
Testing the WCF Web Service: source code
For the Windows form previously created, make modifications to the existing code so it matches with the following:
Imports System.ServiceModel
Public Class Form1
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim proxy As New EmpService.EmpServiceClient("WSHttpBinding_IEmpService")
Dim objEmp As EmpService.Employee = proxy.GetEmployeeInfo(Me.txtEmpno.Text)
proxy.Close()
With objEmp
Me.txtEname.Text = .Ename
Me.txtSal.Text = .Sal
Me.txtDeptno.Text = .Deptno
End With
End Sub
Private Sub btnGetAllNames_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetAllNames.Click
Dim proxy As New EmpService.EmpServiceClient("WSHttpBinding_IEmpService")
Me.lstNames.DataSource = proxy.GetNames
proxy.Close()
End Sub
End Class
Finally, hit F5 to execute and test the application (which accesses and retrieves information from the WCF web service hosted earlier). If everything works fine, you should be able see the output as follows (fig 17):

Figure 17
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. |