1

我是 JDev 和 ADF 的新手,我们需要构建一个可以接收对象数组的 Web 服务。基本上有一个 Dot Net 服务,它会从交换服务器读取电子邮件帐户,并通过使用我们的网络服务发送所有读取的电子邮件。因此 dot net 程序可以从该帐户发送多封电子邮件并发送到我们的网络服务。到目前为止,我们已经创建了接受以下参数的 Web 服务

@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 ...
}

想知道有没有一种方法可以接受可以一次性接收所有电子邮件的对象数组。

4

2 回答 2

1

好的。首先,您应该为 xml 模式生成 XSD 文件 - 对于从 xml 生成类很有用。这是您的示例 .xsd 文件

<?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>

第二件事是从 .xsd 文件生成 C# 和 Java 类。您可以这样做: 1. 从CMD调用 Java 类 2. 从 Visual Studio 命令行xjc -p <package> <path_to_xsd_file.xsd> 调用 C# 类 xsd /C <path_to_xsd_file.xsd>

将您的 java 和 c# 类附加到您的项目中。生成的类应具有C# 和 Java 中的名称root和。messageRootMessage

序列化解析xml,您可以使用如下代码: 1. 在 C# 端 - 序列化为 xml(字符串/字节 [] <- 取决于对您有用的内容)

        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端

        byte[] requestByte;

        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

        Root finalizationParameters = (Root) 
                jaxbUnmarshaller.unmarshal(new ByteArrayInputStream(requestByte));

我希望它会有所帮助。

于 2013-08-01T10:41:46.187 回答
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.

于 2013-07-31T09:59:26.827 回答