user626528
user626528

Reputation: 14409

How to create a redirection for WCF service?

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

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.

Upvotes: 4

Views: 6706

Answers (3)

Greg
Greg

Reputation: 424

If you still need the server to handle other regular traffic including some services, one option is to create an app pool just for redirection that has no managed code.

Example:

IIS With a main site of "Websites" and 2 applications: "WcfServices" and "OtherWebsites"

Say that you want everything to http://Websites/WcfServices to redirect somewhere else.

First, make sure that URL Rewrite and ARR are installed and setup your reverse proxy. (Note that you can change the inbound rewrite rule to point to a specific path as well, not just another server)

Action for Inbound Rewrite Rule with Rewrite URL set to http://internalWebServer:8080/internalWcfServices/{R:0}

Create an app Pool for WcfServices with No Managed Code:

Add Application Pool. Name: WcfServiceRedirect; .NET CLR version: No Managed Code

Make sure that WcfServices uses the new app pool:

WcfServices app's Basic Settings page with Application Pool set to WcfServiceRedirect

At this point, WCF cannot intercept calls to something like http://Websites/WcfService/CustomerDetails.svc since no .net modules can be loaded. All traffic will be routed to the internal server set in the reverse proxy.

Upvotes: 1

Mendhak
Mendhak

Reputation: 8775

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.

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.

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.

Upvotes: 1

Pavel Kovalev
Pavel Kovalev

Reputation: 8116

I'm not sure, but as far as I remember it may happen if you don't have http handler for .svc on web site B

Upvotes: 1

Related Questions