Using NetCFSvcUtil.exe to interact with ServiceContracts

Due to size constraints, only a subset of WCF features were ported over, excluding ServiceContract support. Since then a big request we’ve seen for the .NET Compact Framework is the ability for WCF on devices to be able to interact with servers running ServiceContracts. Currently in order to communicate with a server running a ServiceContract interface it requires that the end-programmer must emulate the XML output of a client connecting to the same ServiceContract interface. Getting examples of the interface, replicating it accurately and handling the server’s response requires additional coding and debugging time for the programmer. In response to this, we have developed the NetCF ServiceModel Metadata Tool (NetCFSvcUtil.exe), modelled after SvcUtil.exe.

 Usage is essentially the same from a command line perspective:

Command Line

SvcUtil.exe http://localhost/ServiceModelSamples/service.svc
NetCFSvcUtil.exe http://localhost/ServiceModelSamples/service.svc

The NetCFSvcUtil will generate two code files from this: The CFClientBase which implements various requirements for interaction and another that implements the client. Simply include these in your .NET Compact Framework project and you will have the ability to interact with ServiceContracts with a minimal of effort. Assuming you’re accessing the Calculator service contained within several of the WCF samples, the following examples show usage which is identical to proxy usage with SvcUtil generated code:

C# Example

CalculatorClient client = new CalculatorClient();
result = client.Add(10.0D, 15.7D);

VB Example

Dim client As CalculatorClient = New CalculatorClient()
Dim result As Double = client.Add(10D, 15.7D)

The NetCFSvcUtil can be found within the .NET Compact Framework Power Toys CTP here: Powertoys for .NET Compact Framework v3.5 CTP (September 2007).

 Of course, the proxies generated by this tool are still subject to the subsest of features from WCF that .NET Compact Framework implements. A list of these can be found on Andrew Arnott’s blog here.

-Dan Horbatt

Comments (4)

  1. David Kline says:

    The .NET Compact Framework team made an exciting CTP available this week.  The .NET Compact Framework

  2. The .NET Compact Framework team made an exciting CTP available this week.  The .NET Compact

  3. An Introduction to WCF for Device Developers Chris Tacke OpenNETCF Consulting, LLC November, 2007 Download