集合已经包含地址与方案net.tcp [英] Collection Already Contains Address with scheme net.tcp

查看:150
本文介绍了集合已经包含地址与方案net.tcp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个持续的问题,我一直在研究几天。我正在努力转换一个WCF服务来使用一个动态端口,这个需求终于进入了范围。我最喜欢的方式但是,我收到错误:


System.ArgumentException:此集合已包含方案net.tcp的地址。


我已经在线搜索了一个答案,并且只有找到解决方案,如果该方案是http。我会提供一些代码,帮助那些希望帮助我和他人的人遇到这个问题。



我有一个services.development.config文件。我们的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/>

我们还在client.development.config文件中具有端点地址。

 < endpoint address =net.tcp:// localhost:14613 / PulseServicebinding =netTcpBinding
bindingConfiguration =NetTcpEndPoint contract =PulseService.IPulsename =NetTcpEndPoint/>

现在我对我使用的方法的理解,我能够保留特定的端口这里指定的号码,稍后更改。现在我正在更改端口号的方法是将会话ID添加到基本端口号(这将是14613)。以下代码是这样做的方法。

  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;

//将端口与服务的其余部分分开
//将会话ID添加到端口
//将地址重新放在一起并返回

Uri uri = new Uri(uriString);

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

当我们尝试处理ServiceHost行时,会出现错误。我的问题是:如何解决这个问题,以使其正常运行?



请记住,我已经尝试在services.development.config中注释基地址文件,以及client.development.config文件中的端点地址。在这样做时,我遇到了其他问题,因为我已经评论过这个地址。

解决方案

我已经解决了这个问题我在问这个问题。而不是尝试为服务主机分配另一个URI,我不得不首先清除端点,然后添加我的新服务端点。我所做的唯一变化是对DynamicPort方法。代码跟随:

  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),新的NetTcpBinding(),uri);
}


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. 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.

I have searched online for an answer, and have only found solutions to if the scheme was 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. We have the app.config file separated for specific reasons within the organization.

<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.

<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). 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. 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. 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. The only changes I made were to the DynamicPort method. 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);
}

这篇关于集合已经包含地址与方案net.tcp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆