Search code examples
azureazure-web-roles

Validating the endpoint for Azure hosted service


I have deployed one azure WCF hosted service. I created one service and one service contract. Everything works fine if I call it as below:

http://myexampleservice.cloudapp.net/TestSertvice.svc/Test1

Now, we want to catch all invalid request, which either do not have the correct service name or correct operation name. For example all requests of the form below:

http://myexampleservice.cloudapp.net/TestSertvice12.svc/Test1

Is there any way to do this?

If I call above invalid requests then service returns response status as 404. Is there any possibility that azure traffic manager will degrade the service if it gets too many such requests?

-Manish


Solution

  • This is actually pretty easy to do. So first you will need to catch 404 requests occurring on your instance(s):

    <customErrors mode="On" >
           <error statusCode="404" redirect="~/Errors/Error404.aspx" />
    </customErrors>   
    

    Each time a 404 error occurs the user/consumer will be redirected to Error404.aspx where you can add this event to a local counter (a file or a static variable) or shared counter if you have multiple instances (SQL Azure, Table Storage, ...).

    Take a look at the options you have when configuring the traffic manager:

    enter image description here

    You can setup a monitoring endpoint. This would point to a different page (like /Status/CanBeUsed.aspx). This page should return an HTTP status code different from 200 if it decides that the deployment should not be used (ie: if your local/shared counter contains too many 404 errors). The Traffic Manager will monitor this page and after 3 failed requests it will fail over to a different deployment.