如何在java中创建mime附件soap消息

如何在java中创建mime附件soap消息,java,web-services,soap,mime,mime4j,Java,Web Services,Soap,Mime,Mime4j,我需要将带有mime附件的SOAP消息发送到我的web服务中。我为此编写了以下代码: File file = new File(fileName); DataSource ds = new FileDataSource(file) { public String getContentType() { return "application/zip";// "application/binary"; }

我需要将带有mime附件的SOAP消息发送到我的web服务中。我为此编写了以下代码:

 File file = new File(fileName);
 DataSource ds = new FileDataSource(file) {
            public String getContentType() {
                return "application/zip";// "application/binary";
            }
        };
        UUID ref = UUID.randomUUID();
        SOAPElement refBody = refNode.addChildElement("PackageBody");
        refBody.removeContents();
        packBody.setAttribute("href", "cid:" + ref.toString());
        AttachmentPart attachment = soapMessage.createAttachmentPart(new DataHandler(ds));
        attachment.setContentId(ref.toString());
        soapMessage.addAttachmentPart(attachment);
        //
        Iterator iterator = soapMessage.getAttachments();
        while (iterator.hasNext()) {
            AttachmentPart attached = (AttachmentPart) iterator.next();
            //
            String id = attached.getContentId();
            String type = attached.getContentType();
            System.out.println("Attachment " + id + " has content type " + type);
            if (type.equals("text/xml")) {
                Object content = attached.getContent();
                System.out.println("Attachment contains:\n" + content);
            }
        }
它对我的项目有效,但不正确。如果我随此附件发送sopa请求,我有:

在soap请求中,找到了对不存在的mime附件的引用


如果这是错误的方式,请告诉我如何正确地为java中的soap创建此mime附件。谢谢

查看此示例是否有用:()@ChaitanyaP非常感谢。这对我有帮助