If the WebMethod returns string it gets serialized to xml.
I want to return byte[]
with responding ContentType - can I also specify it?.
Can it be done in ASP.NET web service web method?
If the WebMethod returns string it gets serialized to xml.
I want to return byte[]
with responding ContentType - can I also specify it?.
Can it be done in ASP.NET web service web method?
ASMX web services use SOAP and the content type will always be application/soap+xml
and the content represent xml
. Even if you return a byte[]
from your method this array will be base64 encoded into the soap body.
You can return a byte array from a web service, but it will still be serialised into the response message. (Typically as base-64 in a SOAP XML response.)
If you want to return only the binary content you shouldn't use a web service. Instead you can use Response.BinaryWrite
with a regular page with no html content, or context.BinaryWrite
in a http handler.
Instead of a web service, use a Generic Handler (.ashx).
A Generic Handler accepts get/post requests and gives you the ability to completely control the output via the HttpContext.
I typically use these for sending files (pdfs, etc) to the browser.