SystemWebRouting Integration Sample
The WebRoutingIntegration sample demonstrates the hosting layer's integration with the classes in the System.Web.Routing namespace. The classes in the System.Web.Routing namespace allow an application to use URLs that do not directly correspond to a physical resource. Using Web routing allows the developer to create virtual addresses for HTTP that are then mapped back to actual WCF services. This is useful when a WCF service must be hosted without requiring a physical file or resource, or when services must be accessed with URLs that do not contain files such as .html or .aspx. This sample demonstrates how to utilize the RouteTable class to create virtual URIs that map to running services defined in global.asax.
Note
The classes in the System.Web.Routing namespace only work for services hosted over HTTP.
This example uses WCF to create two RSS feeds: a movies
feed and a channels
feed. The URLs to activate the services do not contain an extension and are registered in the Application_Start
method of the Global
class derived from the HttpApplication class.
Note
This sample only works in Internet Information Services (IIS) 7.0 and later, as IIS 6.0 uses a different method for supporting extension-less URLs.
To use this sample
Using Visual Studio, open the WebRoutingIntegration.sln file.
To run the solution and start the Web development server, press F5.
A directory listing for the sample appears. Note that there are no files with an .svc file extension.
In the address bar, add
movies
to the URL, so that it readshttp://localhost:[port]/movies
and press ENTER.The movies feed appears in the browser.
In the address bar, add
channels
to the URL, so that is readshttp://localhost:[port]/channels
and press ENTER.The channels feed appears in the browser.
Close the Web browser, by pressing ALT+F4.
If the development server has not exited, right-click the notification area icon and select Stop.
To use this sample when hosted in IIS
Using Visual Studio, open the WebRoutingIntegration.sln file.
Build the project, by pressing Ctrl+Shift+B.
Create a Web application in Internet Information Services (IIS) Manager.
In IIS Manager, right click the Default Web Site and select Add an Application.
For the alias, type in
WebRoutingIntegration
.For the Physical Path, select the Service folder inside the project.
Press OK.
Start the application, by right-clicking the Web application and selecting Manage Application and then Browse.
In the address bar, add
movies
to the URL, so that is readshttp://localhost:[port]/movies
and press ENTER.The movies feed appears in the browser.
In the address bar, add
channels
to the URL, so that is readshttp://localhost:[port]/channels
and press ENTER.The channels feed appears in the browser.
Close the Web browser, by pressing ALT+F4.
This sample demonstrates that the hosting layer is capable of composing with the classes in the System.Web.Routing namespace for routing the requests of services hosted over HTTP.
Note
You must update the default application pool version to .NET Framework 4 if it's set to version 2.