Demo of native code client to WCF services and native code web service using Windows Web Service API

I have uploaded the solution I have been using during MVP summit to demonstrate Windows Web Services API. This solution demonstrates three things:

  1. Using WWSAPI, it is possible two build both clients and web services completely in native code.
  2. Both clients and web services built using WWSAPI can interoperate with WCF based clients and web services and exchange data between them.
  3. Avoiding managed-native code Interop when it comes to presenting a native code computational engine as a web service can have significant performance advantages. In this demo, the native code wrapper of the native code computational engine is 4-6 times faster than managed code wrapper because of the cost of managed-native code interop.

You may download the solution from MSDN Code Gallery page located here. This sample has one solution with five projects.

  1. SortLibrary
    1. This is a native code DLL with two exports that both WCF and WWSAPi based services will call.
    2. First export is a function that implements InsertionSort algorithm. This represents one of the best possible cases of managed-native code Interop. InsertionSort is one function call that takes byte array. There is minimal cost of marshaling and managed/native context switch.
    3. Second function implements QuickSort() algorithm. This represents the worst-case scenario for managed-native code interop. In this case, the algorithm asks its caller to implement a callback that the algorithm is going to use to compare elements. This results in very chatty interface between managed and native code. Of course, this significantly increases the cost of managed – native code interop in this case.
  2. Sort Service using WCF
    1. This is a WCF based service. It wraps Sort Library and allows remote callers to pass data to SortLibrary.DLL. Once SortLibrary.Dll returns back the sorted data, this service returns the data back to clients.
  3. Sort Service Host using WCF
    1. This is the host process that we use to launch the WCF service. Once started, it going to start Service Host object and the service is going to process request from its clients.
  4. Sort Client using WCF
    1. This is the client application build using WCF. Initially it is setup to talk to WCF service. However a small change to <endpoint address=https://localhost:8080/SortService ../> in app.config from https://localhost:8080/SortService to https://localhost:8080/FastSortService will redirect this client to talk to the service built in native code using WWSAPI.
  5. SortService using WWSAPI
    1. This is a web service built 100% in native code using WWSAPI. Similarly to SortService built with WCF, this web service wraps SortLibrary.DLL and enables remote callers pass data to SortLibrary.dll and returns the data back to them.
  6. SortClient using WWSAPI
    1. This is a native code client to both WCF and WWSAPI based services. Initially it is setup to talk to the native code service. However, with a small change on the line #66 in SortServiceClient.cpp, you can redirect this client to talk to WCF based service. To be specific,
      1. With this value of the URL, the client will communicate with the native code web service

        WS_STRING url = WS_STRING_VALUE(L"https://localhost:8080/FastSortService");

      2. With this value of the URL, the client will send data to the web service built in managed code using WCF

        WS_STRING url = WS_STRING_VALUE(L"https://localhost:8080/SortService");

To build this demo, you need to have Visual Studio 2008 SP1 with Windows SDK for Windows 7 installed on your computer. You can build it from Visual Studio or using command line script in the root folder of the demo. To build 32 bit version, run build_demo_x86.cmd. To build 64-bit version, run build_demo_x64.cmd.

To run this demo, you need to prepare your machine to run WCF samples using One-Time Set Up Procedure for WCF Samples. After you are done with this, you may start the demo using either launch_demo_x86.cmd or launch_demo_x64. Here what you should expect after you launch the demo:

  1. Two new command line windows should start on the background. One of them will print "SortService using WCF is up and running...". Another one will print "SortService using WWSAPI is up and running...". These are web services that clients going to access.

  2. In the command prompt window where you have launched the demo, the program will ask you to enter the name of the file. You can enter either big.txt or small.txt.

    Sort Client built using WCF is up and running

    Please enter the path to the file: small.txt

  3. The Client is going to send data to the service. Once it receives it back, the client prints out the amount of time this roundtrip took.

    >launch_demo_x86.cmd

    Sort Client built using WCF is up and running

    Please enter the path to the file: small.txt

    Type the number of the sort algorithm to use:

    0- Insertion Sort

    1- Quick Sort

    2- Both

    Your Choice >> 2

    Insertion Sort Total Time: 00:00:00.2808018

    Quick Sort Total Time: 00:00:01.2480080

  4. After that another native code client is going to start. Again enter either big.txt or small.txt:

    Sort Service Client built using WWSAPI is running...

    Please enter the path to the file: small.txt

  5. The Client is going to send data to the service. Once it receives it back, the client prints out the amount of time this roundtrip took.

    Sort Service Client built using WWSAPI is running...

    Please enter the path to the file: small.txt

    Type the number of the sort algorithm to use:

    0- Insertion Sort

    1- Quick Sort

    2- Both

    Your Choice >> 2

    Insertion Sort Total Time: 0.437 seconds

    Quick Sort Total Time: 0.312 seconds

  6. The demo will stop. You can now close two windows that represent the services by switching focus into them and clicking any button.

Please note that this sample is provided solely to demonstrate a possible use of the API. It is not meant to be a production quality code. It is provided are provided "AS IS" with no warranties, and confer no rights. Use of this sample is a subject to the terms specified at https://www.microsoft.com/ info/cpyright.htm. If you have any questions or comments on the demo, please send me your feedback.