是否可以使用WCF REST Starter套件的RequestInterceptor实现重定向器/反向代理

StackOverflow https://stackoverflow.com/questions/6054310

  •  15-11-2019
  •  | 
  •  

我正在尝试使用来自WCF REST启动器套件的RequestInterceptor来实现反向代理。我能够设置基本标题属性并配置调用。我被困在以下几个方面:

  1. 返回适当的响应 - 我的webservice可以返回文本+ XML,图像或JSON。我无法发送适当的响应类型。邮件.CreateMessage过载是所有SOAP对齐的I.E。它们只接受XML构造,因此我无法发送JSON或图像流。我需要将它们转换为xelements - 我肯定会在这里做错事。

  2. 我还希望在饼干,gzip / deflate和ssl的存在下运行反向代理。

    基于上述要求,您认为使用REST Starter套件做这件事是有意义的吗?RequestInterceptor相当容易插入,但其余的代码正在驱使我坚果。

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top