java - Web service accepting array of object -
i new jdev , adf, have requirement build web service can receive array of object. there dot net service read email account exchange server , send read emails consuming our web service. dot net program can send more 1 email account , send our web service. of have created web service accepts parameters like
@webmethod public string createhdafile(@webparam(name = "sender") string sender, @webparam(name = "primaryrecipient") string primaryrecipitant, @webparam(name = "secondaryrecipient") string secondaryrecipitant, @webparam(name = "subject") string subject, @webparam(name = "messagebody") string messagebody, @webparam(name = "attachmentname") string attachmentname ){ code ... }
want know there way can accept array of object can receive emails in 1 go.
ok. first of all, should generate xsd file xml schema - useful class generation xml. that's example .xsd file
<?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 generating c# , java classes .xsd file. can that: 1. java classes call cmd xjc -p <package> <path_to_xsd_file.xsd>
2. c# classes call visual studio command line xsd /c <path_to_xsd_file.xsd>
attach java , c# classes projects. generated classes should have names root
, message
in c# , root
, message
in java.
to serialize , parse xmls can use code this: 1. @ c# side - serialization xml (string/byte[] <- depends useful 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. @ java side
byte[] requestbyte; unmarshaller jaxbunmarshaller = jaxbcontext.createunmarshaller(); root finalizationparameters = (root) jaxbunmarshaller.unmarshal(new bytearrayinputstream(requestbyte));
i hope helpful.
Comments
Post a Comment