开发者

retrieve a file through .net webservice

In .net web services is there a way where the file name can be sent in the SOAP request and the service returns the File itself as attachment in the SOAP response. I was thinking if the file can only be returned as a filestream object or some sort of .net I/O related object but not as an attachment. I was asked to check if this can be done? Any thoughts or comments开发者_JS百科?


What do you mean by attachment? A SOAP response represents XML encoded data which is sent to the client. Binary structures such as byte[] will be base64 encoded and sent in the response body. So the following method should do the job:

[WebMethod]
public byte[] GetFile(string filename) 
{
    // Add security checks, etc... as such method is begging for hacks
    return File.ReadAllBytes(filename);
}

Also you should probably consider using WCF because ASP.NET web services are considered now as deprecated technology. There are also protocols over HTTP such as MTOM that support optimized binary data transmission over the wire.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜