WCF & Microsoft CRM don't really like each other

time to read 4 min | 761 words

Last week I spent about half a day trying to get WCF to reliabely work against Microsoft CRM web services.

I had plenty of trouble just getting the authentication to work, which I blame solely on my lack of experience in configuring WCF. The problem is that it is literally four lines of code in ASMX, and configuration + code in WCF, which you have to get just right. A big issue there was that authentication failure in the CRM services (ASMX, basically), will return an HTML page explaining the problem, and WCF was willing to give me just the first 1024 bytes of it.

Resorting to black magic hackery to get the real error message is nasty, I am not sure what to blame here, but I would say that WCF is to blame here for not showing the full error message even in the trace logs.

My current problem with this is that the response from the CRM looks something like this:

<RetrieveResult xmlns="http://schemas.microsoft.com/crm/2006/WebServices" xsi:type="account">


       <ownerid name="Oren Eini" dsc="0" type="systemuser">{48D20A98-5F04-DC11-AF65-000C29955492}</ownerid>

       <name>oren eini2</name>



But WCF will return to me an object with all the fields set to null. The problem is that the result message has a lot more properties, and therefor, tags in it. The CRM web service appernatly pick and choose what it will send, and doesn't bother to send empty tags for null proeprties. In the above message, the account entity has ~175 properties, so that is somewhat understandable. The problem is that there is no easy way to make WCF understand that.

After running svcutil over the wsdl, I got a C# file that was 2MB (!!) in size, so manual intervention is out, and there seems to be no easy way to do globally. Playing with the options of svcutil also shows that WCF really doesn't like that WSDL (in fact, it refused to generate DataContracts, instead relying on XML Serialization).

Again, I am not really a WCF expert, but from my experiments, that may be possible, but it is complex, non-DRY, and not worth the trouble. I am using ASMX services now, which just works.