Friday, July 08, 2005

SOAP carrying Attachments

Well, it is very simple. I am using IBM WebSphere v5.1, and it uses Axis, so this should work well with Apache-Axis also.

Getting directly to the point:
A simple java class, which we will expose as a web service:
Method is:

public DataHandler getFileAttachment(String fileName) throws Exception
{
DataSource src = new FileDataSource(fileName);
DataHandler result = new DataHandler(src);
return result;
}

That's it. DataHandler, DataSource and FileDataSource are from javax.activation package.

Just expose this as a WebService and you are all set to receive files from a Web Service, as an attachment to the SOAP message.
A sincere advice, never use byte[] getFile() as a Web Service method, even for a small file, it takes so much time, transferring one byte at a time.

Enjoy!

1 Comments:

At June 21, 2007 at 6:57 AM, Anonymous Anonymous said...

Call for Papers Announced for SOA India 2007
This is definitely interesting information and will be trigger a lot of heated discussions on the subject. On a related note, a first of its kind conference on SOA, SaaS, BPM, MDM, Agile, BPEL, BI, Enterprise 2.0 is being held in India (Bangalore) later this year. If you are responsible for business optimisation, designing, developing and/or implementing your organisation's IT strategy this conference -- SOA India 2007 -- will equip you with the tools and information you need to implement a company wide SOA solution that deploys agile, manageable and secure technology. The Call for Papers was announced recently. Proposals can be submitted to: www.soaindia2007.com. The deadline for submission is 30 June.

 

Post a Comment

<< Home