Dotnet datatype raises error reading utf-16 from mess.queue

greysgreys Member Posts: 29
edited 2015-09-21 in NAV Three Tier
Hi,

I'm currently upgrading legacy code to benefit from the latest dotnet techniques. I've used Rashed Amini's example (http://mibuso.com/blogs/ara3n/2011/04/02/integrating-with-msms-using-dotnet-data-types-in-nav-2009-r2/) to make a connector that can read message queues with dotnet datatypes:

Datatypes:
Q DotNet System.Messaging.MessageQueue.'System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
QMsg DotNet System.Messaging.Message.'System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
MyVariant Variant
Q := Q.MessageQueue(PathToQueue);
Q.Formatter :=  QActiveXFormatter.ActiveXMessageFormatter;

IF TryPeek THEN BEGIN
  QMsg := Q.Peek(TS.TimeSpan(0,0,1));
END ELSE BEGIN
  CLEAR(ReceiveMSMQ);
  ReceiveMSMQ.SetTryPeek;
  IF ReceiveMSMQ.RUN THEN
    REPEAT
      QMsg := Q.Receive(TS.TimeSpan(0,0,10));
      CLEAR(MyVariant);
      MyVariant := QMsg.Body;
      CLEAR(XmlDomDotNet);
      XmlDomDotNet := XmlDomDotNet.XmlDocument;
      XmlDomDotNet.LoadXml(FORMAT(MyVariant));

      i += 1;
      
      FurtherProcessingOfThisMessage(XmlDomDotNet);

      COMMIT;
      CLEAR(XmlDomDotNet);
      CLEAR(ReceiveMSMQ);
      ReceiveMSMQ.SetTryPeek;

    UNTIL (NOT ReceiveMSMQ.RUN) OR (i = 25);
END;
CLEAR(QMsg);
CLEAR(Q);
CLEAR(XmlDomDotNet);

When the message body is of utf-8 nature, all goes well and the xml from the body can be extracted perfectly using an xmlport in the function FurtherProcessingOfThisMessage(XmlDomDotNet). However, when the body is utf-16, the code MyVariant := QMsg.Body raises the error 'A call to System.Messaging.Body failed with the message: Cannot deserialize the message passed as an argument. Cannot recognize the serialization format'.

Since the queue is feeded from a third party program that can only send in utf-16, I'm facing a problem here. Anyone with a solution? Is there a way to format the body to utf-8 before it's assigned to the variant?


Best regards
Josh
Sign In or Register to comment.