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
Comments
Anonymous
May 22, 2009
This post seems to indicate that only basicHttpBinding works. Are there problems with using any other WCF binding?Anonymous
June 22, 2009
Dentro de los requisitos que debemos tener en cuenta en el desarrollo de soluciones de sincronizaciónAnonymous
June 22, 2009
Dentro de los requisitos que debemos tener en cuenta en el desarrollo de soluciones de sincronizaciónAnonymous
June 22, 2009
Dentro de los requisitos que debemos tener en cuenta en el desarrollo de soluciones de sincronizaciónAnonymous
June 21, 2010
I'm using CF v3.5 and I don't find assemblies Microsoft.Synchronization, Microsoft.Synchronization.Data and Microsoft.Synchronization.Data.SqlServerCe. Did you try your code whith this framework? I've a WCF service with BasicHttpBinding endpoint and I got a error CFFaultException. Do you have any Idea? ThanksAnonymous
January 10, 2012
i need help please , i am trying to synchronise a pda data base with a sql server 2008 db can you help me too use sync please. what do you mean by "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." i have this probleme and i don't understand what is your solutionAnonymous
January 10, 2012
The comment has been removed