Good and Bad news about WCF for Windows Mobile

Given this post primarily contains a rant about WCF support within the .NET Compact Framework (ie Windows Mobile), I’ll start with the good points.

  • Further to a previous post on WCF for Windows Mobile the team at Microsoft have released an updated version of NetCFSvcUtil.exe that fixes the issue running under Vista SP2 and Windows 7.  You can download it directly from their blog post on the NetCFSvcUtil QFE (great way to ship updates – an obscure blog that no-on.
  • There is a great whitepaper put together by a couple of MVPs talking about using WCF from the .NET Compact Framework: http://wcfguidanceformobile.codeplex.com/.

Ok, so now for the bad news.

  • If you’re thinking about using Basic Authentication, you can forget WCF.  There is no support for nearly any practical scenario for using WCF unless you want to roll out X509 certificates.  Honestly, whoever didn’t think that Basic Auth over SSL would be good to support…..
  • If you want to share types between client and server, think again. It appears that the /reference and /excludeType flags don’t work as they do with svcutil.exe which means a lot of messing around if you want to share types.
  • No built in support within Visual Studio for doing “Add Service Reference”

If you’re like me and spend most of your time in Visual Studio the last point is a real kick in the head – you mean I have to run NetCFSvcUtil from the commandline, Urgh!  At this point I went “forget it – too hard, too broken, not worth the pain” and went back to “Add Web Reference” (which btw works for WCF endpoints that are configured with basicHttpBinding).  This works well with both basic authentication and SSL so suits my scenario.

Now the issue I have with “Add Web Reference” is that it does silly things with certain types.  For example Guids get converted to string.  It also means that if you have two services (eg ServiceA.svc and ServiceB.svc that use the same type (eg Customer) you will end up with multiple types created on the client (eg ServiceA.Customer and ServiceB.Customer). The solution to this lies within the References.cs file that gets generated – this file contains all the types that get created as part of creating the proxy.  If you remove all the additional generated classes (eg ServiceA.Customer).  This will of course cause compile errors because the referenced types can’t be resolve.  To fix this, add a reference to the assembly that contains the type and then add a using statement to the reference.cs to import the missing types.

One last point – In order for this to work you will probably have to annotate your shared types with xml attributes. For example:

[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://myschemas/DataTransferObjects")]
public class Customer
{

I do wish that Microsoft would do something about the dire state of affair around WCF from .NET Compact Framework, but in the meantime I’d still with Add Web Reference.

Leave a comment