Swami goes Techie

Here i would share my insights on technologies.

Thursday, September 10, 2009

URL Rewriting/Redirecting for Web Service(s) – But How?

Getting Started:

I am trying out with a simple URL redirection technique; if I am successful in this approach I will go ahead in implementing friendly RESTful urls for my application. But it’s not happening the way I desired though.

Problem Definition:

I am facing problem in URL redirection while using HTTP handler technique;

I have created a VisualStudio2008 web service application.

Added 2 services, Service1.asmx and Service2.asmx.

Scenario 1:

Added an HTTP handler (GenericHandler) class in the same hierarchy. 

Added the below code in ProcessRequest method,

if (context.Request.PhysicalPath.IndexOf("Service1.asmx") > -1)

                    context.RewritePath("~/Service2.asmx");

Registered the Handler in the HTTP handler section of the webconfig, the bold one

<remove verb="*" path="*.asmx"/>

<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>

<add verb="*" type="RESTWS.RESTHandler,RESTWS" path="*.asmx"/>

Now, I run my application by making Service1.asmx as the start page, the process hits my handler code, executes it with out any exception, but at last I see a blank screen in the browser.

For crossing my code I also did the following,

Scenario 2:

Added a Global.asax file in the in the same hierarchy.

Added same code in Application_BeginRequest

if (Context.Request.PhysicalPath.IndexOf("Service1.asmx") > -1)

                Context.RewritePath("~/Service2.asmx");

Commented out the Handler registry part what I added in the webconfig.

Again ran the application, the redirection from Service1.asmx to Service2.asmx happened successfully as expected.

Scenario 3:

When I have both the Global.asax and the http handler enabled, again I get a blank page.

Scenario 4:

I felt that HTTP handler does not support url redirection in the case of asmx(web services), so I tried the same above procedures and scenarios with VisualStudio2008 Web application with 2 aspx pages (Default1.aspx and Default2.aspx) instead of Web service application. But the results were same as the above scenarios.

My Questions:

What is the mistake I am doing in my above scenarios?

How to perform url redirection for web services using Http Handlers?

Looking fwd:

Some help and suggestions extended in this regard will be greatly appreciated.

Labels: , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home