Nothing really fancy for our WCF service, the default functions created with the WCF Application should suffice.
First, add a new project to the RussUnitTestSample solution:
Right click solution -> Add -> New Project…
WCF -> Wcf Service Application. Named RussUnitTestSample.Wcf
Your newly added project should look similar to:
Next, we’ll want to configure our project to have multiple start up projects (both the console app, and the wcf service), additionally we will add the WCF service as a service reference in the console application.
Multiple startup projects. Right click solution -> Properties
Select multiple startup projects, change the combo boxes so both the console application, and the wcf application are set to “start”
Find the port the WCF service is set to run on next. Right click the WCF project -> properties
Copy the URL highlighted for use in the next step
Next, we’ll add the WCF project as a service reference to the console application.
In the console application, Right click “References” -> Add Service Reference…
Paste the URL copied before (localhost:portNumber/) -> Discover -> Drill into
service and select your interface (IService1)
Your project should now display a new Folder “Service References” and have the service reference listed. Additionally notice my app.config file has been automatically checked out, as WCF endpoint information has been added.
Here is what was added to the config file
Now our service reference is all added and ready, let’s test it! Modify the
Program.cs of the console application with:
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
Program.cs should now look like:
Give it a run and:
Now our WCF service is hosted, and successfully consumed in the console application. Diff in previous and current can be found on GitHub, note a lot of files in the pull request are auto-generated from the WCF service.
Next, we’ll look at how to test it.