如何创建WCF服务重定向? [英] How to create a redirection for WCF service?
问题描述
我主持在我的网站A.一个WCF服务,我有另外一个网站B,一个重定向到使用IIS的URL重写我的网站的所有请求。然而,站点B不处理任何请求.SVC文件,返回404未找到。任何想法如何使它工作?
I have a WCF service hosted on my website A. And I have another site B, that redirects all requests to my site A using IIS URL rewriting. However, site B doesn't handle any requests to .svc files, returns 404 not found. Any idea how to make it working?
UPD重定向配置是这样的:
UPD redirection config is like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url=".*" />
<action type="Rewrite" url="http://localhost/site_A/{R:0}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我发现没有到.SVC在网站A的IIS日志文件的任何请求(!)。它不重定向这些请求到现场A.然而,当我从站点B要求.htm文件,就其重定向到站点A正确。
I've found that there is no any requests to .svc files in the IIS logs of website A (!). It doesn't redirect these requests to site A. However, when I request .htm files from the site B, it redirects them to site A correctly.
推荐答案
即使你在IIS添加一个.SVC处理程序和重定向它以同样的方式为你做的.HTM请求重定向不会preserve邮件的正文。因此,在SiteB中一个服务方法的要求不一定是一样的站点A服务的方法调用 - 这取决于你的配置,无论是暴露REST风格,你的绑定是什么。
Even if you were to add a .SVC handler in IIS and redirect it in the same manner as you do the .HTM requests, the redirection will not preserve the body of the message. So a request to a service method on SiteB will not necessarily be the same as a service method call on SiteA - this depends on your configuration, whether it is exposed RESTfully, and what your bindings are.
您可以看看 WCF 4.0的路由功能。这要求你写一定的逻辑认识到一个呼叫,并调用它的另一个端点。
You can have a look at WCF 4.0's Routing feature. This requires you to write certain logic to recognize a call and have it call another endpoint.
一个较粗略的解决办法是干脆SiteB中承载它简单地接受传入的请求,并要求站点A的等价的服务,得到结果,并返回给调用者的代理服务。
A 'cruder' solution is to simply have SiteB host a proxy service which simply accepts incoming requests and calls SiteA's equivalent service, gets the result and returns it to the caller.
这篇关于如何创建WCF服务重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!