Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# uri的注册已存在_C#_Wcf_Ninject_Ninject Extensions - Fatal编程技术网

C# uri的注册已存在

C# uri的注册已存在,c#,wcf,ninject,ninject-extensions,C#,Wcf,Ninject,Ninject Extensions,我正在一个通用的WCF主机上工作,它扫描一个插件文件夹并加载实现IWebService类型的所有程序集 然后,我使用Ninject开始托管wcf服务。 所有配置都在App.config中 当只有一个插件要加载时,这非常有效 但是,当我尝试启动第二个时,它抛出一个异常,声明URI的注册已经存在 我在App.config中定义了两个完全不同的服务,所以我真的很困惑 这是App.config <services> <service name="GenericWebSer

我正在一个通用的WCF主机上工作,它扫描一个插件文件夹并加载实现IWebService类型的所有程序集

然后,我使用Ninject开始托管wcf服务。 所有配置都在App.config中

当只有一个插件要加载时,这非常有效

但是,当我尝试启动第二个时,它抛出一个异常,声明URI的注册已经存在

我在App.config中定义了两个完全不同的服务,所以我真的很困惑

这是App.config

 <services>
      <service name="GenericWebService.WebService" behaviorConfiguration="defaultBehavior">
        <host>
          <baseAddresses>
            <!-- note, choose an available port-->
            <add baseAddress="http://localhost:8092/GenericWebService/service" />

          </baseAddresses>
        </host>
        <endpoint address="http://localhost:8092/GenericWebService/service" name="service1" 
                  binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="GenericWebService.ICalculator"/>
      </service>

      <service name="GenericWebService.WebService2" behaviorConfiguration="defaultBehavior">
        <host>
          <baseAddresses>
            <!-- note, choose an available port-->
            <add baseAddress="http://localhost:8093/GenericWebService2/service"/>
          </baseAddresses>
        </host>
        <endpoint address="http://localhost:8093/GenericWebService2/service" name="service2" 
                  binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="GenericWebService.ICalculator2" />
      </service>
    </services>

经过大量重构后,我已经开始工作了,但我不知道它是否“正确”。为了让它工作,我必须在我的webservice类中创建一个新的IKernel,并让它从NinjectModule继承并在其中配置绑定。为什么我需要多个内核才能做到这一点?我应该补充一点,如果我不需要Ninject,那么通过使用标准ServiceHost

总是包含完整异常,包括stacktrace和内部异常。您可以检查IEnumerable Web服务中有多少IWebService吗?列表中有两项,因为我正尝试启动两个服务。提到的例外情况是内部ex。外部ex是无效的操作。在进行了大量重构之后,我会尽快发布堆栈,我已经做到了,但我不知道它是否“正确”。为了让它正常工作,我必须在我的webservice类中创建一个新的IKernel,并让它从NinjectModule继承并在其中配置绑定。为什么我需要多个内核才能做到这一点?我应该补充一点,如果我不需要Ninject,这可以通过使用标准ServiceHost来实现
private static void StartNinjectSelfHostFromPlugin(IEnumerable<IWebService> webServices )
        {
            foreach (var webService in webServices)
            {
                var ninjectType = (new NinjectServiceSelfHostFactory()).GetType();
                var wcfConfiguration = typeof (NinjectWcfConfiguration)
                    .GetMethod("Create", Type.EmptyTypes)
                    .GetGenericMethodDefinition()
                    .MakeGenericMethod(new[]
                    {webService.GetType(),ninjectType })
                   .Invoke(null, new object[]{});
                var x = new NinjectSelfHostBootstrapper(CreateKernel, wcfConfiguration);
                _selfHostBootstrappers.Add(x);
                x.Start();
            }
        }
System.InvalidOperationException: The ChannelDispatcher at 'http://localhost:809
2/GenericWebService/service' with contract(s) '"ICalculator"' is unable to open
its IChannelListener. ---> System.InvalidOperationException: A registration alre
ady exists for URI 'http://localhost:8092/GenericWebService/service'.
   at System.ServiceModel.Channels.UriPrefixTable`1.RegisterUri(Uri uri, HostNama
eComparisonMode hostNameComparisonMode, TItem item)
   at System.ServiceModel.Channels.HttpTransportManager.Register(TransportChanne
lListener channelListener)
   at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListene
r channelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTranspor
tManagersCallback selectTransportManagerCallback)
   at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan time
out)
   at System.ServiceModel.Channels.HttpChannelListener`1.OnOpen(TimeSpan timeout
)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   --- End of inner exception stack trace ---
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at Ninject.Extensions.Wcf.SelfHost.NinjectWcfSelfHost.Start()
   at Ninject.Web.Common.SelfHost.NinjectSelfHostBootstrapper.Start()
   at TestApp.Program.StartNinjectSelfHostFromPlugin(IEnumerable`1 psoWebService
s) in c:\Users\william.davis\Documents\Visual Studio 2013\Projects\Service\TestA
pp\Program.cs:line 80