开发者

How to return both stream and file length from WCF Restful json webservice?

开发者 https://www.devze.com 2023-04-07 04:22 出处:网络
Hihi all, I am able to return stream from my WCF restful json webservice, everything works fine. But when I mixed the stream with 开发者_Python百科another piece of data (both wrap into a custom class

Hihi all,

I am able to return stream from my WCF restful json webservice, everything works fine. But when I mixed the stream with 开发者_Python百科another piece of data (both wrap into a custom class), upon consuming the webservice from my client, it gives an error message of "An existing connection was forcibly closed by the remote host".

Any advice how can I achieve the above? What it's required for my webservice is to allow downloading of a file with the file length as an additional piece of information for validation at the client end.

Thanks in advance! :)


There are various restrictions while using Stream in WCF service contracts - as per this MDSN link, only one (output) parameter or return value (of type stream) can be used while streaming.

In another MSDN documentation (this is anyway a good resource, if you want to stream large data using WCF), it has been hinted that one can combine stream and some input/output data by using Message Contract. For example, see this blog post where author has used explicit message contract to upload both file name & file data. You have to do the similar thing from download perspective.

Finally, if nothing works then you can always push the file length as a custom (or standard such as content-length) HTTP header. If you are hosting in IIS then enable ASP.NET compatibility and use HttpContext.Current.Response to add your custom header.

0

精彩评论

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