A registration already exists for URI - How to programmatically check / remove registration?

二次信任 提交于 2020-01-25 10:06:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!