I have image files stored in hard drive with their address stored as a field in database.
say for example, I would have CUSTOMER_ID would have "C:\IMAGE_CUSTOMERID.jpg" as its image address stored in as a varchar2 field and I want to send the actual image IMAGE_CUSTOMER_ID.jpg inside a web service.
How would you advice sending such files inside a web service. I read about sending it as binary, but can you post a sample example?
In general, sending files via web services is not recommended - specially the media files because of their potential size. Alternatives to sending the file via web service would be to make the file available via ftp or similar and send the filename/location via web service. Another option is to use JMS to send the file (but again, depending on the size this may or may not be a good idea but it definitely works better than web service).
In the past people also sent files via base64 encoding. This encoding essentially turns an image into text, which can be embedded inside a SOAP message. You can find plenty of code samples on Google to encode an image into text and decode it back to image. Again, this may make the soap message way too big and isn't a preferred method anymore.
The problem with web service attachments is that lack of supported standards. While MTOM/XOP is currently the preferred standard it is only supported by the most recent SOAP web service stacks. Earlier clients will only support a variety of even less well supported standards like DIME (not well supported under Java) and SOAP with Attachments (SwA) (not supported under .NET).
Given that you want to expose standard images it makes sense that you expose them as resources: