如何在自托管 WCF 中获取多部分表单数据? [英] How to get multi-part form data in a self hosted WCF?

查看:60
本文介绍了如何在自托管 WCF 中获取多部分表单数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很长时间,但没有找到我要找的东西.我在 Windows 应用程序中自行托管了一个 http WCF.现在在我的服务方法之一中,我需要接收一个文件和一些表单数据字段.在类似的问题中,案例要么发送一个文件(通过流式传输数据然后转换它来完成),要么他们在可以打开 Asp.Net Compatibility 以访问 HttpContext 然后获取所有需要的数据的环境中托管 WCF来自 HttpContext.Current.有什么建议吗?

I've been searching for a quite while now and not found what I'm looking for. I've self hosted a http WCF in a windows application. Now in one of my service's methods I need to receive a file and some form data fields. In similar questions the case is either sending one single file (Which is done by streaming data and then converting it) or they have hosted WCF in an environment that Asp.Net Compatibility can be turned on to access HttpContext and then getting all the needed data from HttpContext.Current. Any Suggestions ?

推荐答案

过了一段时间我发现有人已经回答了我的问题.对于任何面临类似问题的人,这里是答案的链接:

After a while I found out that someone has already answered my question. for anyone out there facing a similar problem here is the link to the answer :

https://stackoverflow.com/a/14514351/11797674

此方法也使用流输入,但不适用于单个文件.它还可以管理通过密钥获取多个文件和表单数据.答案中提供的样本有点旧.我建议您检查 git 存储库并按照那里的示例进行操作.对于 Http WCF 来说,它就像一个魅力,它是自托管在不是 Web 应用程序的应用程序类型上,并且 Asp.Net 兼容模式激活不是一个选项(因为会话与 Web 应用程序不同,并且应用程序没有保存 http 上下文)WCF 是自托管的)

this approach also uses stream input but not for a single file. It also can manage to get multiple files and form data by key. the sample presented in the answer is a little bit old. I suggest that you check the git repository and follow the sample there. It works like a charm for Http WCF's that are self hosted on a application type that is not web application and Asp.Net Compatibility mode activation is not a option (Since Sessions are different than web application and no http context is saved by the application which WCF is self hosted on)

这篇关于如何在自托管 WCF 中获取多部分表单数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆