Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
BRH 58
#ASP.NET 55
ASP.NET 50
#DOTNET 49
.NET 40
WCF 21
DOTNET 12
c# 8
windows azure 7
SILVERLIGHT 7

Archive · View All
April 2011 9
March 2011 9
February 2011 8
December 2010 7
November 2010 5
September 2010 5
August 2010 5
May 2011 4
October 2010 4
January 2011 2

Removing .SVC from WCF REST Service

Sep 20 2010 2:33AM by Dhananjay Kumar   

When we call a service , we call it using the extension of the service. For example , if we are calling a WCF service in the service URL .SVC extension is visible. If we want to remove this extension from the service URL , we will use HTTP Module. This article is going to show how we can achieve that.

I got a mail asking question, “How could we remove .SVC from a WCF REST Service?

For example, instead of



Instead of

We need to remove,.svc extension from address of the WCF service.

Let us say, you have a WCF REST Service up and running

http://localhost:58230/Service1.svc/GetMessage

With output

Output

Read here: How to create a WCF REST Service

To remove service extension, we will write a HTTP Module and remove the extension and rewrite the path.

Now to remove .svc follows below steps

  1. Add a class in WCF Application project.
  2. Add the namespace System.Web
  3. Implement the class from IHttpModule

    publicclassRemovesvc : IHttpModule
  4. Before starting of current context take the context path and rewrite the URL.

    context.BeginRequest += delegate
    {
        HttpContextcxt = HttpContext.Current;
        string path = cxt.Request.AppRelativeCurrentExecutionFilePath;
        int i = path.IndexOf('/', 2);
        if (i > 0)
        {
            string a = path.Substring(0, i) + ".svc";
            string b = path.Substring(i, path.Length - i);
            string c = cxt.Request.QueryString.ToString();
            cxt.RewritePath(a, b, c, false);
        }
    };

     

    Full source code for

    RemoveSvc.cs

    using System;
    usingSystem.Collections.Generic;
    usingSystem.Linq;
    usingSystem.Web;
    
    namespace WcfService7
    {
        publicclassRemovesvc : IHttpModule
        {
            publicvoid Dispose()
            {
            }       
            publicvoidInit(HttpApplication context)
            {
                context.BeginRequest += delegate
                {
                    HttpContextcxt = HttpContext.Current;
                    string path = cxt.Request.AppRelativeCurrentExecutionFilePath;
                    int i = path.IndexOf('/', 2);
                    if (i > 0)
                    {
                        string a = path.Substring(0, i) + ".svc";
                        string b = path.Substring(i, path.Length - i);
                        string c = cxt.Request.QueryString.ToString();
                        cxt.RewritePath(a, b, c, false);
                    }
                };
            }
    
        }
    }
  5. Now we need to add the HTTP Module in configuration file of WCF Service.


    <system.webServer>
        <modules>
          <addname ="removesvc"type ="WcfService7.Removesvc,WcfService7"/>
        </modules>
      </system.webServer>

    Where, RemoveSvc is name of the class implementing IHttpModule and WcfService7 is the project name (namespace)

    Web.Config

    <?xmlversion="1.0"?>
    <configuration>
      <system.web>
        <compilationdebug="true"targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadatahttpGetEnabled="true"/>
              <serviceDebugincludeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironmentmultipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules>
          <addname ="removesvc"type ="WcfService7.Removesvc,WcfService7"/>
        </modules>
      </system.webServer>
    </configuration>
  6. Now host the service in IIS. [Read here : Hosting WCF Service in IIS ]

    Now when you open WCF REST Service in browser, you can see you are able to call the service without extension ,

    http://localhost:4567/Service1/GetMessage

    Server Without Extension

Tags: #DOTNET, #WCF, #ASP.NET, BRH,


Dhananjay Kumar
49 · 4% · 1198
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • A very promising article. However, doesn't work for me.

    commented on Nov 11 2011 11:37AM
    mantronixfan
    3057 · 0% · 2

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]