开发者

retrieve a file through .net webservice

开发者 https://www.devze.com 2023-01-11 07:29 出处:网络
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

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

精彩评论

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