Share via


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.

Comments

  • Anonymous
    March 03, 2009
    The Windows Web Services API (WWSAPI) is a new "minimalist" web services endpoint library available on

  • Anonymous
    March 11, 2009
    Could you provide a quick example of how to read generic SOAP fault? How can I set tracing level? There is WS_TRACE_API enum, but how it's used?

  • Anonymous
    March 12, 2009
    Hi Chabster, I will put together a quick sample of reading SOAP fault and brief explanation on enabling tracing. Thanks, Nikola

  • Anonymous
    May 08, 2009
    With all the talk about Windows 7 on the client, we haven’t talked much about the server platform that

  • Anonymous
    May 15, 2009
    Thanks everyone for attending the session on building web services in C++ code during TechEd 2009! I

  • Anonymous
    May 15, 2009
    On this page, you can find links to all resources available for connecting C and C++ code and web services.

  • Anonymous
    June 16, 2009
    Hi, I have a WCF service which has exposed events. public interface IMyEvents    {        [OperationContract(IsOneWay = true)]        void ClientDisconnect(User user);    } I am tring to create a C++ proxy for this WCF service using WsUtil.exe. While doing so I am getting an error message as "There is no input binding information for operation 'ClientDisconnect'. As a result no files are generated" Please let me know if we can generate proxy for WCF services with events exposed, if so some sample code shold be of great help. Please provide me the information as soon as possible.

  • Anonymous
    August 17, 2009
    When attempting to build on VS2008 Express edition, i get an error WS_NON_RPC_LITERNAL_OPERATION : undeclared identifier. I am unable to find this identifier anywhere on the net.

  • Anonymous
    October 07, 2009
    To Nithy:     In Win7 version of the WWS, the dual sessions are not supported using the Service Model level of APIs. We have built a sample for this scenario using the channel layer of the APIs. And I about to finish it up and publish it. To Si1ver1ock, This error is most likely caused by wrong version of Windows 7 SDK integrated with the VC++ Express. Make sure you have the final RTM version of Windows SDK.

  • Anonymous
    October 27, 2009
    I'm having the same problem of Si1ver1ock, but I'm testing under Win7 + VS2010beta2. I'll try install the final RTM version of WinSDK over the one come with VS10b2.

  • Anonymous
    January 16, 2010
    WS_NON_RPC_LITERNAL_OPERATION is misspelled!! Replace it with: WS_NON_RPC_LITERAL_OPERATION

  • Anonymous
    January 16, 2010
    To NikolaD, After replacing misspelled WS_NON_RPC_LITERNAL_OPERATION to WS_NON_RPC_LITERAL_OPERATION, VC was able to compile past the 'undeclared identifier". Now I am getting the following error: fatal error C1311: COFF format cannot statically initialize '_sortservice_wsdlLocalDefinitions' with 2 byte(s) of an address Can you help me on this issue? Thank. Bizhan

  • Anonymous
    January 23, 2010
    Downloading the Release Candidate (RC) version solved the compile issue (COFF format...) as posted previously. When I run the demo using launch_demo_x86.cmd, I get the following error: "This application has failed to start because webservice.dll was not found." Can anyone help? -Bizhan