Link to home
Start Free TrialLog in
Avatar of Abirami Rajendran
Abirami RajendranFlag for United States of America

asked on

Web Service Application Path

How can we get the application path for a webservice?
In ASP.NET we can use HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)

But 'HttpContext' doesnt work inside a web service.

Can some body help? Thanks

Avatar of strickdd
strickdd
Flag of United States of America image

You can use the ServerVariables: SERVER_NAME and URL

HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + HttpContext.Current.Request.ServerVariables["URL"]
Avatar of Abirami Rajendran

ASKER

Thanks for the reply
I cant use the SERVER_NAME and URL as i dont want to hard-code the name & httpcontest doesnt worh inside a web service. So i cant use server.mappath.
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again. System.Web.Current.HttpContect.Request.ServerVariables("SERVER_NAME") doesnt seems to be working in the class that i have in my webservice. It gives error.

AppDomain.CurrentDomain.BaseDirectory seems to give the path but "\bin\Debug"
If you give the error, I might be able to help debug it. I did just notice I had some namespaces reversed though. You need to do:

System.Web.HttpContext.Current.Response.ServerVariables

instead of

System.Web.Current.HttpContect.Request.ServerVariables

I have a .Net 2.0 and .Net 1.1 webservice that use this same code for error handling.
Thanks. When I try to use System.Web.HttpContext.Current.Response.ServerVariables i get the error
'ServerVariables' is not a member of 'System.Web.HttpResponse'
Change "Response" to "Request" and you should be set.
Thanks. I did but this i what i get as error Referenced object has a value of 'Nothing'.
Okay. I figured the problem. In development env. I have a vb form that calls the web service. So when the vb form calls the web servce, there is no HttpContext. so I get the error, When the service is hosted and i try to call from the VB app it works. Thanks !!