简体   繁体   English

集合已包含方案net.tcp的地址

[英]Collection Already Contains Address with scheme net.tcp

I have a persistent problem, which I have been researching for a couple days now. 我有一个持续存在的问题,我已经研究了几天。 I am working on transitioning a WCF service to use a dynamic port, a need has finally come into scope for this. 我正在努力将WCF服务转换为使用动态端口,对此终于有了需求。 I am most of the way there; 我在这里的大部分时间; however, I am getting the error: 但是,我得到了错误:

System.ArgumentException: This collection already contains an address with scheme net.tcp. System.ArgumentException:此集合已包含一个使用方案net.tcp的地址。

I have searched online for an answer, and have only found solutions to if the scheme was http. 我已经在网上搜索了答案,并且仅找到有关方案是否为http的解决方案。 I will provide some code, to aid those who desire to help me and others with this problem. 我将提供一些代码,以帮助那些希望帮助我和其他人解决此问题的人。

I have a services.development.config file. 我有一个services.development.config文件。 We have the app.config file separated for specific reasons within the organization. 由于组织内的特定原因,我们将app.config文件分开。

<service name="MLITS.Pulse.Pulse" behaviorConfiguration="PulseCSBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:14613/PulseService"/>
      </baseAddresses>
    </host>
    <endpoint name="NetTcpEndPoint"
              address=""
              binding="netTcpBinding"
              contract="MLITS.Pulse.IPulse" />
    <endpoint name="NetTcpMetadataPoint"
              address="mex"
              binding="mexTcpBinding"
              contract="IMetadataExchange" />

We also have the endpoint address in a client.development.config file. 我们还在client.development.config文件中具有端点地址。

<endpoint address="net.tcp://localhost:14613/PulseService" binding="netTcpBinding"
bindingConfiguration="NetTcpEndPoint" contract="PulseService.IPulse" name="NetTcpEndPoint" />

Now it is my understanding with the method I'm using, I am able to keep the specific port number specified here, and later change it. 现在,我对所使用的方法有了了解,可以保留此处指定的特定端口号,以后再进行更改。 Now the way I'm changing the port number is adding the session id to the base port number (which would be the 14613). 现在,我更改端口号的方式是将会话ID添加到基本端口号(将是14613)。 The following code is the method that does just that. 以下代码就是执行此操作的方法。

public static void DynamicAddress()
{
    int sessionIdentification = 0;
    int portNumber = 0;
    int newPort = 0;
    string uriString = string.Empty;

    sessionIdentification = Process.GetCurrentProcess().SessionId;
    portNumber = 14613;
    newPort = portNumber + sessionIdentification;

    uriString = "net.tcp://localhost:" + newPort + "/PulseService";

    //seperate the port from the rest of the service
    //add the session id to the port
    //put the address back together and return it

    Uri uri = new Uri(uriString);

    ServiceHost objServiceHost = new ServiceHost(typeof(Pulse), uri);
}

The error appears when we try and process the ServiceHost line. 当我们尝试处理ServiceHost行时出现错误。 My question is: How do I resolve this, for it to function correctly? 我的问题是:如何解决此问题,使其正常运行?

Keep in mind, I have tried commenting out the base addresses in the services.development.config file, as well as the endpoint address in the client.development.config file. 请记住,我尝试注释掉services.development.config文件中的基地址以及client.development.config文件中的端点地址。 When doing this I have ran into other issues that were because I've commented the address out. 在执行此操作时,我遇到了其他问题,因为我已将地址注释掉了。

I have resolved the issue I was having in regards to this question. 我已经解决了与该问题有关的问题。 Instead of trying to assign the service host with another URI, I had to first clear the Endpoints and then add my new service endpoint. 不必尝试为服务主机分配另一个URI,我必须首先清除端点,然后添加新的服务端点。 The only changes I made were to the DynamicPort method. 我所做的唯一更改是对DynamicPort方法。 Code Follows: 代码如下:

public static void DynamicAddress(
{
    int sessionIdentification = 0;
    int portNumber = 0;
    int newPort = 0;
    string uriString = string.Empty;

    sessionIdentification = Process.GetCurrentProcess().SessionId;
    portNumber = 14613;
    newPort = portNumber + sessionIdentification;

    uriString = "net.tcp://localhost:" + newPort + "/PulseService";

    Uri uri = new Uri(uriString);

    ServiceHost objServiceHost = new ServiceHost(typeof(Pulse));
    objServiceHost.Description.Endpoints.Clear();
    objServiceHost.AddServiceEndpoint(typeof(Pulse), new NetTcpBinding(), uri);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到与方案 net.tcp 匹配的基地址 - Could not find a base address that matches scheme net.tcp 例外:找不到与方案net.tcp匹配的基址 - Exception: Could not find a base address that matches scheme net.tcp 找不到与端点的scheme net.tcp匹配的基址 - Could not find a base address that matches scheme net.tcp for the endpoint 找不到与绑定MetadataExchangeTcpBinding自托管端点的终结点计算机匹配方案net.tcp的基地址 - Could not find a base address that matches scheme net.tcp for the endpoint with binding MetadataExchangeTcpBinding self hosting 找不到与绑定 NetTcpBinding 的端点的方案 net.tcp 匹配的基地址。 基地址方案是 [http] - Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Base address schemes are [http] 使用net.tcp在WCF服务中指定基址的正确方法 - Right way to specify base address in WCF service with net.tcp 确定WCF net.tcp端点地址是否有效 - Determining if a WCF net.tcp endpoint address is valid WCF Web.config 错误:“此集合已包含一个带有方案 http 的地址” - WCF Web.config Error : “This collection already contains an address with scheme http” 获取错误“此集合已包含带有方案http的地址”,本地计算机上有WCF - Getting Error “This collection already contains an address with scheme http” with WCF on local machine 不支持协议&#39;net.tcp&#39; - The protocol 'net.tcp' is not supported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM