Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within I/O and Streams
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
I/O and Streams
How to deserialize object send from .NET
Gurumoorthy Doraiswamy
Greenhorn
Posts: 21
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
i am using .NET UDP server and
java
UDP client. i am converting the class to xml bytes as below in .NET how should i deserialize it java. Do we have any option like canDeserialize
[SerializableAttribute()] [System.Xml.Serialization.XmlTypeAttribute()] [System.Xml.Serialization.XmlRootAttribute()] public class logonReq { [System.Xml.Serialization.XmlAttribute] public string UserID { get; set; } [System.Xml.Serialization.XmlAttribute] public DateTime TimeStamp { get; set; } } private XmlSerializer ser_logonReq logonReq logreq = new logonReq(); logreq.UserID = userid; logreq.TimeStamp = DateTime.UtcNow; using (MemoryStream ms = new MemoryStream()) { ser_logonReq.Serialize(ms, logreq); _message = ms.ToArray(); }
I am trying to use Simple XML in Java. Please help its very urgent.
Gurumoorthy Doraiswamy
Greenhorn
Posts: 21
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I also tried with java serialization as below
JAVA
public class logonReq implements Serializable { public String Deviceid; public String appname; public String TimeStamp; } public static byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(out); os.writeObject(obj); return out.toByteArray(); }
.NET
[SerializableAttribute] [XmlTypeAttribute] [XmlRootAttribute] public class logonReq { [XmlAttribute] public string Deviceid { get; set; } [XmlAttribute] public string appname { get; set; } [XmlAttribute] public string TimeStamp { get; set; } } private static readonly XmlSerializer SerLogonReq = new XmlSerializer(typeof(logonReq)); var memStream = new MemoryStream(Message); var xmlReader = XmlReader.Create(memStream); if (SerLogonReq.CanDeserialize(xmlReader)) { var resultingMessage = (logonReq)SerLogonReq.Deserialize(xmlReader); Logger.DebugFormat("Logon Message from cient ({0})", resultingMessage); LogonMessage(resultingMessage); return; }
[Added code tags - see
UseCodeTags
for details]
But i receive the below error "Invalid character in the given encoding. Line 1, position 1."
Can any one let me know where it is wrong . Its really urgent. Help
Ulf Dittmer
Rancher
Posts: 43081
77
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Post the XML you're working with.
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
content not allowed in prolog exception
Action Class
Add new shapes in slides using serialization
Interoperability
how to calculate the Size of data stored in session
More...