Webservice – Hide WSDL From Other User

If you dont want to allow your client your user to see informtion or Description about your Webservice than it can be done in following way.

Add Global.asax File in you Webservice Application and in that set this two properties by follwing code.

This code shows WSDL and its information to local user and it dows not allow any other remote user to see description of wsdl.

protected void Application_BeginRequest(object sender, EventArgs e)
{
//Request Path
string requestPath = Request.RawUrl.Trim().ToLower();
HttpApplication app = sender as HttpApplication;

if (!IsLocalRequest(app.Context.Request))
{
if (requestPath.IndexOf(“?wsdl”) > 0 || requestPath.IndexOf(“?disco”) > 0)
{
throw new HttpException(403, “Remote access is prohibited”);
}
}

}

// This method determines whether request came from the same IP address as the server
public static bool IsLocalRequest(HttpRequest request)
{
return request.ServerVariables[“LOCAL_ADDR”] == request.ServerVariables[“REMOTE_ADDR”];
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s