2

I am currently working on an application where I am creating a ServiceHost, then getting rid of it, then recreating it later. The problem is that once I get rid of the service host when I try to recreate it I get the exception "A registration already exists for URI after stop/start." The weird thing is I have three separate hosts and one works and two don't. I assume something is not being disposed of properly but I'm not sure why.

I am creating the hosts like this

host = new ServiceHost(typeof(MyService));
host.Open();

Then getting rid of them like so

if (host != null)
{
    host.Close();
    host = null;
}

I have also tried abort instead of close without any luck.

4

1 回答 1

1

虽然我不确定确切的问题,但我可以给你一点想法和一些解决方法。

如果您在 Windows 7 中工作,则您在托管过程中创建的任何 URL 都必须进行注册。Netsh 命令通常可以帮助我们注册和注销 URL。

对于注册和注销 URI,您需要拥有管理员权限。

您可以尝试以下方法。

  1. 如果您正在运行您的 exe,请尝试在管理员模式下运行它。(右键单击并选择管理员模式)。

  2. 如果您正在尝试使用 Visual Studio,请尝试以管理员模式重新启动 Visual Studio 并运行该应用程序。

  3. 尝试取消注册 URI,然后使用 Netsh 重试。

http://saravananarumugam.wordpress.com/2011/03/01/http-could-not-register-url/

可以帮助你。

于 2011-06-01T18:26:18.793 回答