我正在构建基于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
发布评论