1

I am new to JDev and ADF, we have requirement to build a web service which can receive array of object. Basically there is a Dot Net service which will read email account from exchange server and send all the read emails by consuming our web service. So the dot net program can send more than one email from the account and send to our web service. As of now we have created the web service which accepts the 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 to know is there a way we can accept array of object which can receive all emails in one go.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

If You have access to .Net code maybe think about information in XML form? Then it's not a problem to add more than one element with the same tag to XML document. I made something similar (XML messages) between .Net and WS and it works. If You need some code to do that, ask me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.