Thursday, June 11, 2015

WCF: How to get application physical base directory

I am generating a temp file in my WCF and wanted to store in a Temp folder inside my WCF.

HTTPContext does not apply for WCF, so we can't use that to get the base directory

Environment.CurrentDirectory => Will provide you the debug/bin directory

AppDomain.CurrentDomain.BaseDirectory => Will provide you the debug/bin directory as well.

System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath => Will provide you the Application base directory.

Note that, System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath will work only if you host the WCF Service as Web application..

If you host the WCF Service from console, it will always return null.

Wednesday, June 10, 2015

HTTP could not register URL

I was trying to run a service with a non admin user (rmanni), and when I start the service, I got the error

HTTP could not register URL http://+:8080/MyService/. Your process does not have access rights to this namespace


To solve the issue Microsoft said, I need to add the url using netsh command as mentioned here

This command solved it for me

netsh http add urlacl url=http://+:8080/MyService user=myDomain\rmanni