You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by Gabsaga Tata <ga...@simpaq.com> on 2005/09/28 18:45:44 UTC

SOAP attachment Question

Is it possible for a client application to get back data as MIME attachment from a web service?
>From the example code snippets below, the service successfully attaches a file to a SOAP message
but when the client application tries to get the attachments count, it is zero. Any ideas why?

Thanks.

Gabsaga


********************************************************
Code snippet for MyMessageService message-style service.
********************************************************
MessageContext msgCntxt = MessageContext.getCurrentContext();
SOAPMessage msg = msgCntxt.getMessage();
DataHandler dataHander = new DataHandler(new FileDataSource("C:\\<tomcat_directory>\\webapps\\axis\\WEB-INF\\attachments\\res_message.xml"));
AttachmentPart attachment = msg.createAttachmentPart(dataHander);
attachment.setContentId("attached_processed_file");
msg.addAttachmentPart(attachment);

********************************************************
Code snippet for Client application sending request to 
MyMessageService message-style service.
********************************************************
SOAPConnection conn = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage response = conn.call(message, "http://localhost/axis/services/MyMessageService"); 


SOAPPart responseSp = response.getSOAPPart();
SOAPEnvelope responseSe = responseSp.getEnvelope();
SOAPBody responseBody = responseSe.getBody();

//Get attached message
if(!responseBody.hasFault())
{
 int numOfAttachments = response.countAttachments();
 System.out.println("\n\nNumber of attachments in message = " + numOfAttachments);
}
********************************************************



Re: SOAP attachment Question

Posted by Scott Nichol <sn...@scottnichol.com>.
Please post Axis questions to axis-dev@ws.apache.org.

Scott Nichol

Do not send e-mail directly to this e-mail address,
because it is filtered to accept only mail from
specific mail lists.
----- Original Message ----- 
From: "Gabsaga Tata" <ga...@simpaq.com>
To: <so...@ws.apache.org>
Sent: Wednesday, September 28, 2005 12:45 PM
Subject: SOAP attachment Question


> Is it possible for a client application to get back data as MIME attachment from a web service?
> From the example code snippets below, the service successfully attaches a file to a SOAP message
> but when the client application tries to get the attachments count, it is zero. Any ideas why?
> 
> Thanks.
> 
> Gabsaga
> 
> 
> ********************************************************
> Code snippet for MyMessageService message-style service.
> ********************************************************
> MessageContext msgCntxt = MessageContext.getCurrentContext();
> SOAPMessage msg = msgCntxt.getMessage();
> DataHandler dataHander = new DataHandler(new FileDataSource("C:\\<tomcat_directory>\\webapps\\axis\\WEB-INF\\attachments\\res_message.xml"));
> AttachmentPart attachment = msg.createAttachmentPart(dataHander);
> attachment.setContentId("attached_processed_file");
> msg.addAttachmentPart(attachment);
> 
> ********************************************************
> Code snippet for Client application sending request to 
> MyMessageService message-style service.
> ********************************************************
> SOAPConnection conn = SOAPConnectionFactory.newInstance().createConnection();
> SOAPMessage response = conn.call(message, "http://localhost/axis/services/MyMessageService"); 
> 
> 
> SOAPPart responseSp = response.getSOAPPart();
> SOAPEnvelope responseSe = responseSp.getEnvelope();
> SOAPBody responseBody = responseSe.getBody();
> 
> //Get attached message
> if(!responseBody.hasFault())
> {
>  int numOfAttachments = response.countAttachments();
>  System.out.println("\n\nNumber of attachments in message = " + numOfAttachments);
> }
> ********************************************************
> 
> 
>