Changing WCF Base address - wcf

By default the base address for my test wcf application is
http://localhost:8732/Design_Time_Addresses/evalservice
but when I remove the Design_Time_Addresses and go for a simple base address like below
<add baseAddress="http://localhost:8732/evalservice" />
I receive the below error
Please try changing the HTTP port to 8732 or running as Administrator.
System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8732/evalservice/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ---> System.Net.HttpListenerException: Access is denied
and when I move it back to Design_Time_Addresses the issue is resolved.
What is Design_Time_Addresses and how can I change it to a more simple base address?

The Design_Time_Addresses namespace is automatically registered by the .NET framework to allow users without administrator privileges to develop WCF services:
You can modify access using the netsh.exe tool [...] under the elevated administrator account. The following is an example of using netsh.exe.
netsh http add urlacl url=http://+:9002/MyService user=<domain>\<user>
Another workaround would be to run Visual Studio as administrator.

Related

VS2019 Cannot launch .NET Core ASP 2 web site and browse from another computer on the same network

I have been trying to browse a website run under IIS Express VS2019 from another computer on the same network. I see the following error.
Bad Request - Invalid Hostname
I found several discussions where people suggested adding bindings and I did try adding so many different bindings in applicationhost.config with specific hostname, IP, hostname+ip, wildcards. When I add any binding or modify the existing localhost binding VS 2019 start giving me the following error
Unable to connect to web server 'IIS Express'
I am running VS2019 as an admin. What else I am missing?
Here is what I discovered. I do not have admin privileges on my local PC. Our sysadmin had created a shortcut for me which launches VS2019 as an admin. However, the VS was still not run as elevated Admin privileges. Turns out, you need to be an admin, and you must right-click the VS2019 shortcut and choose Run As Administrator with a shield and say Yes to the warning. The shortcut wasn't doing none of that. Now my custom IIS Express bindings are picked up from applicationhost.config without any issue.

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

I just upgraded from Windows 7/VS2010 to a clean install of Windows 8/VS2012.
I'm logging onto a domain user (domain admin) and have started seeing this error when launching some of my wcf services from VS2012:
HTTP could not register URL http://+:10001/. Your process does not have access rights to this namespace
I've never experienced this before on Windows 7 and I'm a little perplexed why I'm seeing this now in Windows 8 (domain admin, user access control turned off).
With some research I found out that this error arises due to the VS process not running with admin rights and non admins apparently can't listen on TCP ports, however, I don't quite follow why VS wouldn't run as admin as the user I'm logging in to is a domain admin?
You must execute something like this:
netsh http add urlacl url=http://+:10001/YourUri/ user=\Everyone
or
netsh http add urlacl url=http://+:10001/YourUri/ user=DOMAIN\user
Something is mentioned in this article or google for "netsh http add urlacl"
AFAIK since Vista processes do not run with elevated privileges even if launched by Admin account. That is the whole point behind UAC.
However after you run netsh command you will not need anything like that anyway.
You can change Account window to administrator in control panel, it's have all permission to run url.
Make sure, you run both the VS and Command prompt as Administrator.
Execute the command on Command Prompt
netsh http add urlacl url=http://+:10001 user=<your_userid>
Open VS as Administrator

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

I'm a beginner in WCF, but trying to improve my experience. And on the first step I faced the problem. I created the simplest WCF service. The listing of code: (all the code in one file)
using System;
using System.ServiceModel;
namespace EssentialWCF
{
[ServiceContract]
public interface IStockService
{
[OperationContract]
double GetPrice(string ticker);
}
public class StockService : IStockService
{
public double GetPrice(string ticker)
{
return 94.85;
}
}
class Service
{
static void Main(string[] args)
{
ServiceHost serviceHost = new ServiceHost(typeof(StockService),
new Uri("http://localhost:8000/HelloWCF"));
serviceHost.AddServiceEndpoint(typeof(IStockService), new BasicHttpBinding());
serviceHost.Open();
Console.WriteLine("To continue press ENTER");
serviceHost.Close();
}
}
}
That would be the service that give me a number via console. But debug give me the exception: (instead of number :) )
HTTP could not register URL http://+:8000/HelloWCF/. Your process does not have access rights to this namespace.
Have you ever faced the same situation? I will be glad to see every advice.
Unfortunately the link in the exception text, http://go.microsoft.com/fwlink/?LinkId=70353, is broken. However, it used to lead to http://msdn.microsoft.com/en-us/library/ms733768.aspx which explains how to set the permissions.
It basically informs you to use the following command:
netsh http add urlacl url=http://+:80/MyUri user=DOMAIN\user
You can get more help on the details using the help of netsh
For example: netsh http add ?
Gives help on the http add command.
I closed Visual studio IDE and reopened it by right clicking on the Visual Studio icon and saying "Run as Administrator", Then when I ran the host , It worked!!!
Right Click on Visual Studio > Run as Administrator > Open your project and run the service.
This is a privilege related issue.
The simple thing you need to do is to close your Visual Studio environment and open it again by using 'Run as administrator'. It should now run successfully.
You need some Administrator privilege to your account if your machine in local area network then you apply some administrator privilege to your User else you should start ide as Administrator...
You must give permission to your app for listening http requests. You can use this command in cmd for this purpose (open cmd Run As Administrator mode)
netsh http add urlacl url=http://+:8000/ user=Everyone
If your app is working other port, for example 9095, this command must be like as below:
netsh http add urlacl url=http://+:9095/ user=Everyone
And re-run your app, it should work.
This way working for me.
In Windows Vista and later the HTTP WCF service stuff would cause the exception you mentioned because a restricted account does not have right for that. That is the reason why it worked when you ran it as administrator.
Every sensible developer must use a RESTRICTED account rather than as an Administrator, yet many people go the wrong way and that is precisely why there are so many applications out there that DEMAND admin permissions when they are not really required. Working the lazy way results in lazy solutions. I hope you still work in a restricted account (my congratulations).
There is a tool out there (from 2008 or so) called NamespaceManagerTool if I remember correctly that is supposed to grant the restricted user permissions on these service URLs that you define for WCF. I haven't used that though...
Your sample code won't work as shown because you forgot to include a Console.ReadLine() before the serviceHost.Close() line. That means the host is opened and then immediately closed.
Other than that, it seems you have a permission problem on your machine. Ensure you are logged-in as an administrator account on your machine. If you are an administrator then it may be that you don't have the World Wide Web Publishing Service (W3SVC) running to handle HTTP requests.
While I was able to solve this problem in one computer following the other users solutions, the command netsh didn't solve the issue in one of my machines and even though the current user had administrator rights I was still getting the "HTTP could not register URL.... Your process does not have access rights to this namespace". So I'm sharing my solution in case you still don't get it to work with the other solutions too.
After also trying to give write permissions to the user in the physical directory of my website and getting no success, I finally decided trying to change IIS settings.
As the images below show, I configured the Physical Path Credentials of my website to connect as an specifc user, which was an admin account with DOMAIN\username and password, and this was enough to make the error disapear.
Close iis express and all the browsers (if the url was opened in any of the browser). Also open the visual studio IDE in admin mode. This has resolved my issue.
I was getting the same error in a for a domain using a different port (2130). The process was a service. I was able to fix the issue by changin the user running the service from NetworkSystem to Local System Account.
Another thing I might add: If this just for local testing purposes you could try to change the port from 8000 to something else such as 8080 and not get this error. That worked for me at least.

ApplicationPool ProcessModel Identity fails when installed via cmd line

I have a WCF service which I install via cmd line, due to installment on many servers!
When installing application pool and configuring it, I set a custom account on the process model identity, which is just an account with local administrator rights!
But when I try to browse the service just to see the front service page I get a Service Unavailable message with http error 503, which is a server error which again comes from an event id 5021, which states that the identity for the service's application pool is invalid due to either incorrect username/password or the user may not have batch logon rights.
Ergo, the error has to do with the user identity! When I change Identity to NetworkService there is no problem. I cannot either manually set the Identity to the user...
My cmd line looks like:
c:\Windows\System32\inetsrv\appcmd add apppool /name:"calendarproviderservice" ^
/autostart:"true" ^
/managedRuntimeVersion:"v4.0" ^
/processModel.idleTimeout:"24:00:00" ^
/enable32BitAppOnWin64:"true" ^
/processmodel.identitytype:"SpecificUser" ^
/processModel.userName:"PlannerAdmin"
Anyone has a clue...?
Cheers, Finn.
It's been a while, but I finally solved my problem! Unfortunately I didn't sketch the hole scenario in the main question because I didn't think it mattedered in the context. But it did!
The scenario was that my server was a deployed server with a base configuration including IIS 7.5! And this is the problem!
When you try to set the application pool identity to a domain account, IIS has to keep a local copy of your username and password. This is stored in IIS applicationHost.config in encrypted format. In the encryption IIS uses the machine specific keys in iisConfiguration and iisWasKey containers. When this applicationHost.config is moved to a different server (in this case the deployed server on new hardware), IIS can no longer decrypt the password because of the new machine keys.
One can export configuration Keys, but I already deleted the base server I made an image of!
So the lesson learned here is: If you have to deploy many servers with IIS on, make a base image WITHOUT IIS, and script the IIS on the server after deployment!!!
Cheers, Finn.
PS. Dominik, sorry that I wasn't that clear on the intro question!
Have you assigned the user to the local IIS_USRS group?

WCF on Windows 7 not working

I am using an example from iDesign about one way calls. I can get it to work on a Vista machine (VS2008) but not on a windows 7 machine (VS2010).
I get this error:
HTTP could not register URL http://+:8001/MyService/. Your process does not have access rights to this namespace
ServiceHost host = new ServiceHost(typeof(MyService));
host.Open();
I get the error on the host.Open(); line. I noticed that windows asks first for some firewall and to give permission which I did but still it is not working. What can I do?
This has to do with how the security for vista and later versions of windows deal with port access. The Post below has the command you need to run.
Take a look at this post
Have you reserved that namespace? The link that is in the exception message tells you how, however as you appear to have missed or not gotten that
Open an elevated command prompt and run
netsh http add urlacl url=http://+:8001/MyService/ user=DOMAIN\user
replacing DOMAIN\user with your account details, or a suitable group