是否可以使用 WCF REST 入门套件中的 RequestInterceptor 实现重定向器/反向代理
我正在尝试使用 WCF REST 入门套件中的 RequestInterceptor 来实现反向代理。我能够设置基本标头属性并配置调用。我遇到了以下几个方面的问题:
返回适当的响应 - 我的 Web 服务可以返回文本+xml、图像或 json。我无法发送适当的响应类型。 Message.CreateMessage 重载都是 SOAP 对齐的,即它们只接受 Xml 构造,因此我无法发送 JSON 或图像流。我需要将它们转换为 XElements - 我在这里肯定做错了什么。
我还希望反向代理能够在 cookie、gzip/deflate 和 SSL 存在的情况下正常运行。
根据上述要求,您认为使用 REST 入门套件来做到这一点有意义吗? Requestinterceptor 相当容易插入,但是其余的代码让我抓狂。
I am attempting to implement a reverse proxy using the RequestInterceptor from WCF REST starter kit. I am able to set the basic header properties and configure the calls. I am getting stuck with the following aspects:
Returning an appropriate response - my webservice can return text+xml, image or json. I am not able to send the appropriate response type. The Message.CreateMessage overloads are all SOAP aligned i.e. they accept only Xml constructs, so I am not able to send either JSON or image streams. I need to convert them into XElements - I am definitely doing something wrong here.
I also want the reverse proxy to be functioning well in the presence of cookies, gzip/deflate and SSL.
Based on the above requirements, do you think it makes sense to do this using REST starter kit? The Requestinterceptor was fairly easy to plug into, however the rest of the code is driving me nuts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON 和任意二进制内容与 WCF 消息中使用的 XML 之间存在映射(请参阅 http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx),因此您可以使用 Message.CreateMessage也可以创建非 XML 消息。
话虽如此,目前在 WCF 中执行此操作确实不直观。 WCF Web API 中的新库 - http://wcf.codeplex.com - 提供了一种非常好的方法拦截/重定向/绕过 WCF 管道,特别是 HTTP 消息。此外,它以本机方式支持多种格式(即,无需对 XML 进行一些映射)。
There is a mapping between both JSON and arbitrary binary content to XML which is used in messages for WCF (see some examples at http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx), so you can use Message.CreateMessage to create non-XML messages as well.
Having said that, it's really not intuitive to do that in WCF as of now. The new libraries in the WCF Web API - http://wcf.codeplex.com - provide a very nice way of intercepting / redirecting / bypassing the WCF pipeline especifically for HTTP messages. Also, it support multiple formats in a native way (i.e., without need to do some mapping to XML).