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

查看:32
本文介绍了支持“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);

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

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

有谁知道在 WCF 中支持application/x-www-form-urlencoded"的更强类型的方式吗?

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);

推荐答案

最好的方法是使用 Stream 就像 使用 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 或制作自己的绑定并实现 自定义编码器.这与链接的帖子所说的输出对称.你必须扭动它的手臂才能让 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天全站免登陆