Using WCF for Communcation in a Mobile Sync Application

In the past few months we have seen a number of posts in our sync forum that have shown questions and issues relating to the use of WCF as the transport layer for a Windows Mobile Sync Services for ADO.NET application. As such, it seemed prudent to post a note with some tips for ways to work around some of the limitations of WCF in the .NET Compact Framework when using devices.

Tips

1) Force the use of [XmlSerializerFormat] for the contract interfaces, as shown in the Iservice.cs code attached below.

2) Force the use of basicHttpBinding for your contracts, as shown in the attached web.config file.

3) Modify the netcfSvcUtil.exe generated service.cs code to remove all the duplicated types that are already defined in the Microsoft.Synchronization.Data.dll. This is most likely the reason users will encounter an InvalidCast exception.

4) Deal with Collection<string> and string[]. as you can see in the sample code below, the attached sample uses string [] to ensure it is consistent in the GetSchema(). This is most likely the cause of an ArgumentException when calling this method.

5) Setting the includeExceptionDetailInFaults="true" flag in the web.config can be helpful for debugging, and some logging logic at the server side could be helpful also as shown in the server side code.

6) When using netcfSvcUtil.exe, just use the default option, to generate the client side code.

7) The following blog is helpful for more information on using WCF on devices: https://blogs.msdn.com/andrewarnottms/archive/2007/09/13/calling-wcf-services-from-netcf-3-5-using-compact-wcf-and-netcfsvcutil-exe.aspx

Additionally, the following WCF sample code will hopefully provide some help to ease some of your frustration.

Yunwen Bai

WCF Devices Code.pdf