Re: Major problems using .NET 3.5 DataContract

Home Page Forums BizTalk 2004 – BizTalk 2010 Major problems using .NET 3.5 DataContract Re: Major problems using .NET 3.5 DataContract

#19322

Mike,
thanks for your reply. I managed to solve this, so will post the messy fix but also the reason why.

THE PROBLEM: When casting XML into an Object or vice-versa, biztalk does this behind the scenes. It can be done manually up to a point (RetrieveAs methods etc) but on the whole, it always uses the XmlSerializer class, which used to be fine. However, with the new .NET 3.x, you can save time and pain when creating the object (data) definitions using DataContracts. Behind the scenes, a new serializer (DataContractSerializer) performs the cast between XML to Object, and vice-versa. Unfortunately, BizTalk cannot/does not use this new serializer, hence on attempting to cast the message, it always fail because the class definition contains non of the information needed by the XMLSerializer.THE FIX:Once it was clear what the problem was, the simple solution was just to decorate the DataContract class with all the attributes needed by the XmlSerializer. (I did this by generating a class from the Schema using XSD.exe, and manually merging this into the DataContract class definition). I don’t like this, it works, but is messey. I’m sure with enough time, it possible to extend the methods BizTalk uses so that the DataContractSerializer is used instead.THE REASONI have integrated X trading partners using Async doc-literal messaging. When a message comes into BizTalk, I map it into a conical format, before passing into a Business Logic Library (BLL) that verifies the data (above schema validation) and inserts into the database.

The BLL is used by both BizTalk to insert/lookup information in the database, and an information portal that also inserts and looks-up information from the Database. There are strict segregation of duties, but it makes sense to have a unified logic layer in this instance.

To ease this link, the BLL accepts parameters of the conical message in object form. However, when BizTalk passes in the parameter, it casts it using the XmlSerializer. The Conical format is defined in the BLL using the DataContractSerializer, hence the problem. With my solution, the BLL continues to work (I think with the DataContractSerializer, not 100% sure but it works), while BizTalk works with the XmlSerializer.I hope this may help someone else!TM