zig*_*zig 4 c# asp.net web-services webforms asmx
而不是在Web方法本身(作为SOAP XML)中返回二进制流(MTOM/Base64编码),例如:
[WebMethod]
public byte[] Download(string FileName)
....
return byteArray;
Run Code Online (Sandbox Code Playgroud)
这种方法可以以某种方式响应(可能通过Server
对象)?:
Response.BinaryWrite(byteArray);
Run Code Online (Sandbox Code Playgroud)
伪:
[WebMethod]
public DownloadBinaryWrite(string FileName)
...
Response.BinaryWrite(byteArray);
Run Code Online (Sandbox Code Playgroud)
对的,这是可能的.注意我将返回类型更改为void,因为我们将直接写入响应,我需要手动设置内容类型并结束响应.
[WebMethod]
public void Download(string FileName)
{
HttpContext.Current.Response.ContentType = "image/png";
HttpContext.Current.Response.BinaryWrite(imagebytes);
HttpContext.Current.Response.End();
}
Run Code Online (Sandbox Code Playgroud)
请注意,WebMethod现在不受支持,您应该切换到Web API或WCF(如果需要SOAP支持).