Cedric,
By returning the Dom as the response, does this make the web service non-portable because the Object is serialized by Java (as I am assuming it is sent as xsd:anyType) - only Java knows how to un-serialize the object ? Is the Dom serialized when returned or passed as plain XML text ?


What does your deploy.wsdd and wsdl file look like for the Document return Type ?




From: Carbone Cedric <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: RE: JAX-RPC with attachments question
Date: Mon, 9 Feb 2004 17:42:23 +0100

This an example i use for my message style Web service. The webService wait
a DOM and response with another DOM and a binary attachment. I have added
several comments in the code following.

Hope this helps,

C�dric Carbone
Neopost France
cca<at>brainsoft.fr


Server side (the Web service) : ------------------------------- public Document SendMessage(Document demand) throws RemoteException, SOAPException { //make your stuff with the org.xml.w3c.Document demand

        //build your DOM answer
        org.xml.w3c.Document response = ...;

        //Bind the attachments (here 2 javax.activation.Datahandler)
        DataHandler dh1 = new DataHandler(new FileDataSource("c:/web.jpg"));
        DataHandler dh2 = new DataHandler(new
FileDataSource("c:/TaskManager.txt"));
        MessageContext messageContext = MessageContext.getCurrentContext();
        org.apache.axis.Message responseMessage =
messageContext.getResponseMessage();
        responseMessage.addAttachmentPart(new AttachmentPart(dh1));
        responseMessage.addAttachmentPart(new AttachmentPart(dh2));

        //return the DOM answer
        return response;
}

Client Side :
-------------
                Element payload = /*the DOM to send to the web service*/ ;

                Service service = new Service();
                Call call = (Call) service.createCall();
                call.setTimeout(this.timeout);
                call.setTargetEndpointAddress(this.endPoint);
                SOAPBodyElement[] input = new SOAPBodyElement[1];
                input[0] = new SOAPBodyElement(payload);
                Vector elems = null;
        //Send
                Vector elems = (Vector) call.invoke(input);

        // Response treatement
                //Extract Attachment(s)
                org.apache.axis.MessageContext messageContext =
call.getMessageContext();
                org.apache.axis.Message returnedMessage =
messageContext.getResponseMessage();
                System.out.println("Number of attachments is -> " +
returnedMessage.countAttachments());
                Iterator iteAtta = returnedMessage.getAttachments();
                DataHandler[] dhTab = new
DataHandler[returnedMessage.countAttachments()];
                for (int i=0;iteAtta.hasNext();i++) {
                        AttachmentPart ap = (AttachmentPart) iteAtta.next();
                        dhTab[i] = ap.getDataHandler();
                        System.out.println("Filename=" +
dhTab[i].getName());
                }

        //Extract XML Payload
                SOAPBodyElement SOAPelem = null;
                SOAPelem = (SOAPBodyElement) elems.get(0);
                Element elemResp = SOAPelem.getAsDOM();


The DOM response is Element elemResp. The attachments received from the server are DataHandler[] dhTab[].

-----Message d'origine-----
De : Steve Pruitt [mailto:[EMAIL PROTECTED]
Envoy� : lundi 9 f�vrier 2004 17:00
� : [EMAIL PROTECTED]
Objet : JAX-RPC with attachments question


I have a service that needs to return xml and an attachment, the xml
contains some meta-information about the attachment. I am using the jax-rpc
api. My question is how to return both an xml document and an attachment.
I can see how to return one or the other, but not both.


Can someone point me to a good example, I can't find one.

Thanks,

-Steve Pruitt

_________________________________________________________________
Plan your next US getaway to one of the super destinations here. http://special.msn.com/local/hotdestinations.armx




Reply via email to