支持“application / x-www-form-urlencoded”的最佳方式使用WCF发布数据? [英] Best way to support "application/x-www-form-urlencoded" post data with WCF?

查看:668
本文介绍了支持“application / x-www-form-urlencoded”的最佳方式使用WCF发布数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建基于W3C规范的WCF服务,该规范定义了接受application / x-www-form-urlencoded发布数据的RESTful Web服务端点。默认情况下,WCF不支持这种类型的消息编码,我发现了一些创建合同的不同示例,如下所示:

I'm building a WCF service based on a W3C specification which defines a RESTful web service endpoint that accepts "application/x-www-form-urlencoded" post data. WCF doesn't support this type of message encoding by default and I have found a number of different examples of creating a contract that looks like this:

XElement Query_Post(Stream postData);

然后在实现解码 postData 使用 HttpUtility.ParseQueryString 方法流。

And then within the implementation decoding the postData stream using the HttpUtility.ParseQueryString method.

有没有人知道更强类型的方式支持application / x-www-form-urlencoded在WCF?

Does anyone know of a more strongly typed way of supporting "application/x-www-form-urlencoded" in WCF?

我希望我的运营合同是:

I would like my operation contract to be:

XElement Query_Post(string query, string [] params);


推荐答案

最好的方法是使用使用WCF进行原始HTTP POST 或您所说的内容。
原因是因为WCF从服务代码中抽象出所有通信级物理布局。理想情况下,您只想通过翻转开关来创建可以变成SOAP或REST的服务。

The best way is to use Stream like Raw HTTP POST with WCF or what you are saying. The reason is because WCF abstracts all the communication-level physical layout stuff out from the service code. Ideally, you would want to make a service that could turn into SOAP or REST just by flipping the switch.

为了本地支持它,您可能需要扩展 WebHttpBinding 或制作自己的绑定并实施 custom编码器。这与链接帖子所说的输出对称。你必须扭转它的武器,让WCF输出非XML / JSON的东西。

To support it natively, you probably have to extend WebHttpBinding or make your own binding and implement custom encoder. This is symmetric to the output like the linked post says. You have to twist its arms to get WCF to output non-XML/JSON stuff.

这篇关于支持“application / x-www-form-urlencoded”的最佳方式使用WCF发布数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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