OK. First of all, you should generate XSD file for xml schema - useful for class generation from xml. That's example .xsd file for you
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="message" type="message"/>
<xs:complexType name="message">
<xs:sequence>
<xs:element name="attachmentName" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="messageBody" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="primaryRecipient" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="secodaryRecipient" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="sender" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="subject" type="xs:string" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="root" type="root"/>
<xs:complexType name="root">
<xs:sequence>
<xs:element name="message" type="message" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Second thing is generating C# AND Java classes from .xsd file. You can do that like that:
1. for Java classes call from CMD xjc -p <package> <path_to_xsd_file.xsd>
2. for C# classes call from Visual Studio Command Line
xsd /C <path_to_xsd_file.xsd>
Attach your java and c# classes to your projects. Generated classes should have names root and message in C# and Root and Message in Java.
To serialize and parse xmls you can use some code like this:
1. At C# side - serialization to xml (string/byte[] <- depends what is useful for You)
MemoryStream stream = new MemoryStream();
root objectRoot = new root();
objectRoot.message = new message[2];
objectRoot.message[0] = new message();
objectRoot.message[0].attachmentName = "msg1";
objectRoot.message[0].messageBody = "mb1";
objectRoot.message[0].primaryRecipient = "pr1";
objectRoot.message[0].secodaryRecipient = "sr1";
objectRoot.message[0].sender = "s1";
objectRoot.message[0].subject = "su1";
objectRoot.message[1] = new message();
objectRoot.message[1].attachmentName = "msg2";
objectRoot.message[1].messageBody = "mb2";
objectRoot.message[1].primaryRecipient = "pr2";
objectRoot.message[1].secodaryRecipient = "sr2";
objectRoot.message[1].sender = "s2";
objectRoot.message[1].subject = "su2";
XmlSerializer serializer = new XmlSerializer(typeof(root));
serializer.Serialize(stream, objectRoot);
byte[] toSend = stream.ToArray();`
2. At java side
byte[] requestByte;
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Root finalizationParameters = (Root)
jaxbUnmarshaller.unmarshal(new ByteArrayInputStream(requestByte));
I hope it would be helpful.