The first thing you will need to do is create a new service based on the WSDL above.

  1. Beginning from scratch – open a new instance of Visual Studio 2013 and create a new WCF Service Library Project called Example.Service. Name the solution Example. Verify that the .NET Framework version selected in the dropdown list is set to .NET Framework 4.5, as shown in Figure 2. Click OK to create the project.



Figure 2 - Creating the Example.Service WCF Service Library project

  1. By default, Visual Studio will create a template interface (IService1.cs) and service implementation class (Service1.cs), which would be used when writing a code-first service. We can safely delete these two files as we will be using a contract first approach - i.e. our service is based on a WSDL. See Figure 3 - New project default files.


Figure 3 - New project default files

  1. Visual Studio comes with a tool called svcutil, which will generate the proxy classes for us, but WSCF.blue makes our life a little easier. In Solution Explorer, right-click on Example.Service and select "Choose WSDL to Implement…" from the WSCF.blue menu. A dialog will appear. Choose the Example.wsdl file you saved from Section 6.2 and complete the information as shown in Figure 4 - WSCF.blue server-side configuration. The following settings are:
    1. Service-side stub – generate the classes for the service side;
    2. Adjust Casing – which simply changes the casing of the classes to match the conventions of C#;
    3. Single Concurrency – A single request has access to the WCF service object at a given moment of time. So only one request will be processed at any given moment of time. The other requests have to wait until the request processed by the WCF service is completed A single request has access to the WCF service object at a given moment of time. So only one request will be processed at any given moment of time. The other requests have to wait until the request processed by the WCF service is completed.
    4. Per-Call Instance – new WCF instances are created for every method call made to the WCF server service. The default concurrency is Single so only one thread will be used to serve all instances.
    5. Use Synchronisation Context – ties WCF to the thread that created the host where applications that need to update some GUI from other threads.
    6. Generate abstract classes – this allows us to inherit from the generated stub, so if we need to regenerate from the WSDL at any point, we don't lose any implementation.



Figure 4 - WSCF.blue server-side configuration

  1. WCSF.blue will add a System.ServiceModel reference to your project, as well as generating the following files:
    1. NewPortType.cs – which contains the Service stub and proxy classes
    2. Output.config – which is service specific configuration that can be added to the host's application configuration file. We aren't going to use this, so it can be safely deleted. The configuration will be done manually, in code.
  2. Within NewPortType.cs there will be an abstract class generated, which will form the basis of our service. See Figure 5 - Service abstract class. Create a new class called NewService.cs and add the code shown in Figure 6 - Service implementation code.



Figure 5 - Service abstract class

Figure 6 - Service implementation code

  1. Compile the External.Service project.


At this point, you've created a set of proxy classes that are used to provide the server side of the service, and the implementation behind to actually do something to handle the requests coming in, as well as send back a response. At this point, the service is complete, but to consume it from a client application, you'll need to host it first.

  • No labels