支持“application / x

编程入门 行业动态 更新时间:2024-10-23 11:22:24
本文介绍了支持“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

本文发布于:2023-10-09 18:23:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476433.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:application

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!