问题
I am hosting my WCF services in service fabric. One of the WCF service starts a HttpSelfHostServer
on a port after startup. I sometimes gets the error:
A registration already exists for URI 'http://localhost:10503/'. at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.CommunicationObject.EndOpen(IAsyncResult result) at System.Web.Http.SelfHost.HttpSelfHostServer.OpenListenerComplete(IAsyncResult result)
In service fabric, I think there could be multiple services spun up by the framework. I am wondering if there is any way to programmatically check the port and detect there is a service registered with it and remove it automatically?
回答1:
https://docs.microsoft.com/en-us/windows/win32/http/show-urlacl
Netsh http show Urlacl command is able to help us to detect the reserved URl. But as you know, we need to elevate the permission to an administrator, then delete or add the entry for the specifical users and accounts(The administrator account can directly remove the occupation and use the reserved URL).
Netsh http add urlacl url=https://+:80/MyUri user=DOMAIN\user
delete urlacl url=https://+:80/MyUri
If it is accomplished programmatically, we need to execute the delete command as an administrator, who can directly remove the occupation and use the reserved URL. Therefore, I don't think it is feasible.
Feel free to let me know if there is anything I can help with.
来源:https://stackoverflow.com/questions/57782319/a-registration-already-exists-for-uri-how-to-programmatically-check-remove-r