Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

Service Bus For Windows Server - Brokered Message Body of type ApplicationException

$
0
0
I would like to transmit a BrokeredMEssage with a body of type ApplicationException between my server and my client but I have a deserialization exception.

I use a custom serializer to `serialize/deserialize` the body of my BrokeredMessage :
public class CustomDataContractBinarySerializer : XmlObjectSerializer
To Read Object and Write Object, I use a DataContractSerializer : 
 public override object ReadObject(Stream stream)
            {
                if (stream == null)
                {
                    throw new ArgumentNullException("stream");
                }
                return base.ReadObject(XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max));
            }
        public override void WriteObject(Stream stream, object graph)
            {
                if (stream == null)
                {
                    throw new ArgumentNullException("stream");
                }
                XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(stream, null, null, false);
                base.WriteObject(writer, graph);
                writer.Flush();
            }
    ...

I have an object of type `ApplicationException` I want to use as bofy of my BrokeredMessage :

      
 [Serializable]
        public class MyApplicationException : ApplicationException
        {
     public MyApplicationException (string message, params object[] args)
                : this(message, null, args)
            {
            }
      public MyApplicationException (string message, Exception inner, params object[] args)
                : this(message, false, inner, args)
            {
            }
      public MissionControlApplicationException(string message, bool displayed, params object[] args)
                : this(message, displayed, null, args)
            {
            }
      public MyApplicationException (string message, bool displayed, Exception inner, params object[] args)
                : base(message, inner)
            {
                this.Displayed = displayed;
                this.Message = message;
                this.Parameters = args;
            }
      public MyApplicationException (
                SerializationInfo info,
                System.Runtime.Serialization.StreamingContext context)
                : base(info, context)
            {
                Message = (string)info.GetString("Message");
    ...
            }
            // this is new
            public override void GetObjectData(SerializationInfo info, StreamingContext context)
            {
                //base.GetObjectData(info, context);
               info.AddValue("Message", Message);
    ...
            }
    ...

}

To create my BrokeredMessage, I do like this:
 var outboundMessage = new BrokeredMessage(body, new CustomDataContractBinarySerializer(typeof(MyApplicationException )));

When my client receives my object, I do like this to deserialize: 
var stream = brokeredMessage.GetBody<Stream>();
      var customDataContractBinarySerializerException = new CustomDataContractBinarySerializer(typeof(E));
      object messageException = CustomDataContractBinarySerializerException.ReadObject(stream);

But I got an exception on the ReadObject method: (RunTime 

There was an error deserializing the object of type `xxx.xxx.xxx.MyApplicationException`. The input source is not correctly formatted.

And the call stack:
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
       at System.Xml.XmlBufferReader.ReadValue(XmlBinaryNodeType nodeType, ValueHandle value)
       at System.Xml.XmlBinaryReader.ReadNode()
       at System.Xml.XmlBinaryReader.Read()
       at System.Xml.XmlBaseReader.IsStartElement()
       at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
       at System.Runtime.Serialization.XmlReaderDelegator.IsStartElement(XmlDictionaryString localname, XmlDictionaryString ns)
       at System.Runtime.Serialization.XmlObjectSerializer.IsRootElement(XmlReaderDelegator reader, DataContract contract, XmlDictionaryString name, XmlDictionaryString ns)
       at System.Runtime.Serialization.DataContractSerializer.InternalIsStartObject(XmlReaderDelegator reader)
       at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
       at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)

Does anyone know how I can solve this?






Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>