In VS2015, I wanted to create the very simplest possible WCF service, and a client, in the form of a console app, to prove it works.
In VS, use the WCF template to create a WCF service library. As the template is a Hello World, I choose to call it HelloAcmeService (I don’t know why I’m randomly picking fictitious brands):
That creates an interface file, and a class file, which contain more than I want, so we strip those back to a minimum, and do some renaming.
…removing the stuff I don’t want, and some renaming:
After an OK build let’s make sure we can reference it from the browser, by pressing Start in VS , and then clicking on the BaseAddress hyperlink in the app.config (or just typing it in):
Now we could plug the WSDL into SoapUI and get a richer client experience (if those words mean nothing, that can be for another tutorial). For now, we’ll just create a console app to use the service.
Stop the service running in VS, so you can go back to editing. Create a console app under the solution (please note – there is in fact a compile error later using this name for reasons I am not going into here, and I won’t redo the screenshots – please call the console app HelloServiceAClient – note the ‘A’):
That gives you this new content in the Solution Explorer:
You now need to add a Service Reference to use the service from this client. Right click on References/Add Service Reference…, and in the dialogue, click Discover:
Click OK, and Solution Explorer now looks like this:
Now in Program.cs, add the text highlighted to access the service and use the GetData() method from the service:
The last action before testing it is to right-click on HelloServiceAClient and select Set as Startup Project.
Now press the Play button in VS, and you get this exciting output: