You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by Adam Kaminiecki <ad...@dgt.com.pl> on 2011/02/16 11:31:44 UTC

sending ObjectMessage between C# and Java

Hi,

Can anybody tell me how to get body form ObjectMessage in C#  or 
properly send from Java??
Everything work ok for TextMessage but when I send  text message from 
Java in ObectMessage in C# client occur an error

where IMessage m
((IObjectMessage) m).Body = '((IObjectMessage) m).Body' threw an 
exception of type 'System.Runtime.Serialization.SerializationException'

System.SystemException {base} = {"input stream is not a valid binary 
format. The content of the initial (in bytes):.......


But when I send From C# it is ok.


Any ideas how can I fix my problem??


Best regards,
Adam

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


Re: sending ObjectMessage between C# and Java

Posted by Jim Gomes <e....@gmail.com>.
The NMS API has some good support for automatically serializing C# objects
into XML format and back out into objects.  You can refer to the
XmlMessageTest.cs unit test in the Apache.NMS project for some sample code
on how to go about this.

If you are using the .NET 3.5 assemblies (or later version, or Mono), then
there are several extension methods that make the syntax very nice.  The
XmlMessageTest.cs file shows two examples -- one using extension methods
(the preferred way), and one without, for .NET 2.0 and earlier.

I use these functions heavily to pass objects back and forth between C# and
Java.

On Wed, Feb 16, 2011 at 6:27 AM, Adam Kaminiecki <ad...@dgt.com.pl> wrote:

> Hi.
>
> You are right. After investigation a can tell you now and Im SURE Its
> impossible to send ObjectMessage between clients (C# is not able to get body
> from this type of message in Java it is possible after workaround :) ). Only
> solution is serialize object to XML and then send it as TextMessage. Thats
> work fine!
>
>
> Regards,
> Adam
>
>
>
> W dniu 2011-02-16 12:49, Timothy Bish pisze:
>
>  On Wed, 2011-02-16 at 11:31 +0100, Adam Kaminiecki wrote:
>>
>>> Hi,
>>>
>>> Can anybody tell me how to get body form ObjectMessage in C#  or
>>> properly send from Java??
>>> Everything work ok for TextMessage but when I send  text message from
>>> Java in ObectMessage in C# client occur an error
>>>
>>> where IMessage m
>>> ((IObjectMessage) m).Body = '((IObjectMessage) m).Body' threw an
>>> exception of type 'System.Runtime.Serialization.SerializationException'
>>>
>>> System.SystemException {base} = {"input stream is not a valid binary
>>> format. The content of the initial (in bytes):.......
>>>
>>>
>>> But when I send From C# it is ok.
>>>
>>>  C# cannot de-serialize a java Object, it doesn't know anything about the
>> byte java types or how they are encoded.  You can send C# objects to C#
>> clients if they know about the type you are sending but that's the limit
>> of what you can do with ObjectMessage in C#.
>>
>> If you really need to send objects then you should look into using
>> something like XStream to convert them to XML and then parse the XML on
>> the C# side.
>>
>> Regards
>>
>>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>

Re: sending ObjectMessage between C# and Java

Posted by Adam Kaminiecki <ad...@dgt.com.pl>.
Hi.

You are right. After investigation a can tell you now and Im SURE Its 
impossible to send ObjectMessage between clients (C# is not able to get 
body from this type of message in Java it is possible after workaround 
:) ). Only solution is serialize object to XML and then send it as 
TextMessage. Thats work fine!


Regards,
Adam



W dniu 2011-02-16 12:49, Timothy Bish pisze:
> On Wed, 2011-02-16 at 11:31 +0100, Adam Kaminiecki wrote:
>> Hi,
>>
>> Can anybody tell me how to get body form ObjectMessage in C#  or
>> properly send from Java??
>> Everything work ok for TextMessage but when I send  text message from
>> Java in ObectMessage in C# client occur an error
>>
>> where IMessage m
>> ((IObjectMessage) m).Body = '((IObjectMessage) m).Body' threw an
>> exception of type 'System.Runtime.Serialization.SerializationException'
>>
>> System.SystemException {base} = {"input stream is not a valid binary
>> format. The content of the initial (in bytes):.......
>>
>>
>> But when I send From C# it is ok.
>>
> C# cannot de-serialize a java Object, it doesn't know anything about the
> byte java types or how they are encoded.  You can send C# objects to C#
> clients if they know about the type you are sending but that's the limit
> of what you can do with ObjectMessage in C#.
>
> If you really need to send objects then you should look into using
> something like XStream to convert them to XML and then parse the XML on
> the C# side.
>
> Regards
>

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


Re: sending ObjectMessage between C# and Java

Posted by Timothy Bish <ta...@gmail.com>.
On Wed, 2011-02-16 at 11:31 +0100, Adam Kaminiecki wrote:
> Hi,
> 
> Can anybody tell me how to get body form ObjectMessage in C#  or 
> properly send from Java??
> Everything work ok for TextMessage but when I send  text message from 
> Java in ObectMessage in C# client occur an error
> 
> where IMessage m
> ((IObjectMessage) m).Body = '((IObjectMessage) m).Body' threw an 
> exception of type 'System.Runtime.Serialization.SerializationException'
> 
> System.SystemException {base} = {"input stream is not a valid binary 
> format. The content of the initial (in bytes):.......
> 
> 
> But when I send From C# it is ok.
> 

C# cannot de-serialize a java Object, it doesn't know anything about the
byte java types or how they are encoded.  You can send C# objects to C#
clients if they know about the type you are sending but that's the limit
of what you can do with ObjectMessage in C#.

If you really need to send objects then you should look into using
something like XStream to convert them to XML and then parse the XML on
the C# side.

Regards

-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/