Major problems using .NET 3.5 DataContract

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

Viewing 1 reply thread
  • Author
    Posts
    • #19314

      Hi everyone,
       
      I am having major issues defining data contracts and using the svcutil generated schemas, any help would be appreciated.
       
      1) I have created a DataContract class in VS2008. This holds all the messages in conical format i intend to send into BizTalk.
      2) I generated an XSD (schema) from this using svcutil (command: svcutil /dconly /d:..\Schema ..\bin\Debug\XLabData.dll)
      3) I added the XLabData.dll as a reference to my BizTalk project (in VS 2005) so I could cast messages into objects.
      4) I added the XSD from 2 into my BizTalk project so I could use it.
       
      This all compiles down and deploys fine. Implying the casting etc is deemed acceptable. I do get a compiler warning though, which I cannot figure out as the namespace do match Tongue Tied I do not change the schema after it was generated.
       
      http://XLabData.Messages Warning 24 the namespaces do not match for the XSD types ‘XLabIntegration.Schema.Internal.XLabDataMessages.ACK’ in ‘c:\documents and settings\administrator\my documents\visual studio 2005\projects\xlabintegration\xlabintegration.schema.internal\obj\development\xlabintegration.schema.internal.dll’ and ‘XLabData.Messages.ACK’ in ‘c:\documents and settings\administrator\desktop\xlabdata.dll’ C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\XLabIntegration\XLabIntegration.Orch.LimsInterface\InBound\InBoundInterface.odx 895 110

       

      5) In a BizTalk orch expression shape, I attempt to cast the incoming message into its .NET class equivalent.
      6) I get exceptions when attempting to do so. I have given this exception below for a message of type Message (lol). FYI previously, I ran xsd.exe on the XSD fom 2 to re-generate the class file, and then used this in my BizTalk project [instead of the dataContract class from 1]. If I use this class when casting, it works. However the DataContact class is used in the Business Logic Layer (XLabData.dll), which I cannot change, so I have to use that. I decorated all the classes with [Serializable] however this did not do the trick Sad

       

      I could really use some help as to why this won’t work.

      Thanks to all!

      TM

       

      Event Type: Error
      Event Source: XLANG/s
      Event Category: None
      Event ID: 10034
      Date:  11/04/2008
      Time:  22:26:30
      User:  N/A
      Computer: XLABV2DEV1
      Description:
      Uncaught exception (see the ‘inner exception’ below) has suspended an instance of service ‘XLabIntegration.Orch.LimsInterface.InBoundRequest(8f4911ff-f32b-f2e5-8eb4-4912d8231fd0)’.
      The service instance will remain suspended until administratively resumed or terminated.
      If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
      InstanceId: df6d3e0f-f2b6-4472-b700-06eabe06e9c8
      Shape name: Save Request
      ShapeId: 76a1442f-a6df-42ce-88fd-8072a12ed8ee
      Exception thrown from: segment 2, progress 2
      Inner exception: There is an error in XML document (1, 2).
             
      Exception type: InvalidOperationException
      Source: System.Xml
      Target Site: System.Object Deserialize(System.Xml.XmlReader, System.String, System.Xml.Serialization.XmlDeserializationEvents)
      The following is a stack trace that identifies the location where the exception occured
         at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
         at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
         at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
         at Microsoft.XLANGs.RuntimeTypes.XmlHelpers.ObjectFromStream(Stream s, Type t)
         at Microsoft.XLANGs.Core.Value.GetObject(Type t)
         at Microsoft.XLANGs.Core.Value.RetrieveAs(Type t)
         at Microsoft.XLANGs.Core.Part.ProtectedRetrieveAs(Type t)
         at Microsoft.XLANGs.Core.Part.RetrieveAs(Type t)
         at XLabIntegration.Orch.LimsInterface.InBoundRequest.segment2(StopConditions stopOn)
         at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)
      Additional error information:
              <Message xmlns=’http://XLabData.Messages’&gt; was not expected.
             
      Exception type: InvalidOperationException
      Source: jhdeukaw
      Target Site: System.Object Read11_Message()
      The following is a stack trace that identifies the location where the exception occured
         at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMessage.Read11_Message()
             
      For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

    • #19320

       Hi TM,

      Can you clarify more on the technical requirements that implied designing the BizTalk solution based on WCF datacontracts??

      Mike 

      • #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 

        • #19340

          ahhh my formatting keeps getting screwed up on posting.

          Appologies for the post looking like crap, I tried to edit it twice to no avail.

          TM

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.