I noticed that a few people are looking at my old blog post for WCF. While that may have been a way to do things, there is a much easier way now. It’s not to say that you still cant do it that way, but in an interest of saving some time. I would like to investigate the built in tools for WCF that comes with Visual Studio 2008. I am using the .net framework 3.5 SP1.
Here are some simple steps to create a wcf service and test project to use it:
1. Open a new vs2008 instace and create a windows project.
2. In that same solution, create a new web site (right click solution, new web site). In that dialog instead of asp.net website choose WCF Service
3. Build the web project (it comes with default wcf interfaces for two services, one is a simple call, and the other uses a composite type to pass back and forth as samples)
4. Add 1 testbox and two buttons to your winform project.
5. Add a service reference to your winform project and click the discover button. Rename your namespace to WCFWebTest. If you want to use aync calls, then click the advanced button on the add servicec reference dialog and select the Gnerate async operations.
6. In the button1 click event add the following code:
Dim oWCFService As New WCFWebTest.ServiceClient
Dim response As String = oWCFService.GetData(TextBox1.Text)
MessageBox.Show(response)
7. In the button 2 click event add the following:
Dim oWCFService As New WCFWebTest.ServiceClient
Dim oCompositeType As New WCFWebTest.CompositeType
oCompositeType.StringValue = "My String Value YAY! "
oCompositeType.BoolValue = True
Dim oCompType As CompositeType = oWCFService.GetDataUsingDataContract(oCompositeType)
MessageBox.Show(oCompType.StringValue)
8. Run the web project (set it as default) and debug the winform project like described in the article.
Viola! That just works with a LOT less work.