Using WCF Services with Smart Client Application

WindowsMobileLogo The current project I am assigned to at work is Smart Client application running own Windows CE that communicates with WCF Services that it uses to communicate with SAP via BizTalk Services.  We choose to use WCF because of the power that we felt it would bring to the solution.  What we didn’t realize was the limited support in Visual Studio for consuming WCF Services for a Smart Client application.

In a WinForms application you have two choices to add an Application Reference to your project you can use the SvcUtil.exe or you can right click on the References node of the solution and select Add Application Reference.  In the Smart Client world you don’t have either option, you can try to use the SvcUtil.exe but it will not create a proxy that can compile against NetCF libraries because NetCF does not include all the classes referenced from that source code.

Fortunately we found the Power Toys for .NET Compact Framework 3.5 which contains NetCFSvcUtil.exe that could be used to generate NetCF complaint service proxies.  Once install the power toys you will find the NetCFSvcUtil.exe in the C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\bin directory.

We setup a batch file to generate the service files for us.  So, all we had to do was make sure we check out the files and then run the command file to update the proxies and check the files back in and we are good.

You should be aware that NetCF does not support all WCF Bindings, it supports: BasicHttpBinding, CustomBinding, WindowsMobileMailBinding, and ExchangeWebServiceMailBinding.  Andrew Arnott has a post about The WCF subset supported by NetCF and other good information.

A good friend and member of our team Devlin Liles, has put together a great post, Batch File and Command File running in Visual Studio, to show how you can execute a command file from the Visual Studio IDE and use the output window for any text.  I highly recommend you check it out.

NetCFSvcUtil.exe http://localhost/MyService.svc

This will generate the CFClientBase.cs and the MyService.cs files we need to access the WCF Service.  If you want to control the namespace that the proxies get created in you can use the /namespace argument to specify this.

NetCFSvcUtil.exe namespace:*,MyNameSpace.Proxies http://localhost/MyService.svc

Likewise you can also control where the files are generated by using the /directory argument.

NetCFSvcUtil.exe namespace:*,MyNameSpace.Proxies http://localhost/MyService.svc /directory:../MyApp/Proxies

There are a lot of other options you can use to control how the proxies are generated you can execute NetCFSvcUtil.exe /? to see all of them and what they do.

This gets you up and running with WCF Services in a Smart Client application, without the robust configuration that is offered with WinForms or WebForm projects.  In my next post I will walk you through how we configured our WCF Service endpoints and set some custom binding information to control how our clients behaved when consuming the services.

blog comments powered by Disqus


<<  April 2021  >>

View posts in large calendar

Month List