在WCF app.config中,为什么基地址需要前缀http://或net.tcp?

Nib*_*Pig 1 wcf

我正在观看WCF上的网络广播,它在app.config中定义了两个端点,一个netTcpBinding和一个mexHttpBinding.

它还有两个基地址,net.tcp://localhost:9000http://localhost:8000.

我想知道它是如何将这些基地址与端点相关联的.由于您的端点指定了tcp或http,为什么基地址以net.tcp和http为前缀?

如果WCF使用net.tcp基地址和netTcpBinding端点,如果你有两个tcp端点监听9000和9001会发生什么,你会在配置中放置什么来阻止冲突?

Moh*_*and 6

我想知道它是如何将这些基地址与端点相关联的.

按协议.

定义服务端点时,可以为端点提供相对或绝对地址,如果给出绝对端点地址,则不会使用基址来生成实际端点地址,但是如果在端点中给出相对地址,则您的基地址和相对地址的组合将用于生成最终端点地址.

相对端点地址就像这样:

  <endpoint address="/hostHttp"  binding="wsHttpBinding"  contract="IMyService" />
  <endpoint address="/hostNetTcp"  binding="netTcpBinding"  contract="IMyService" />
Run Code Online (Sandbox Code Playgroud)

现在,WCF将使用您根据协议定义的基址生成实际端点地址:

<baseAddresses>
            <add baseAddress="http://localhost:8550/MyServiceHost/Service"/>
            <add baseAddress="net.tcp://localhost:8551/MyServiceHost/Service"/>
</baseAddresses>
Run Code Online (Sandbox Code Playgroud)

所以你的HTTP端点地址最终将是:

http://localhost:8550/MyServiceHost/Service/hostHttp
Run Code Online (Sandbox Code Playgroud)

和你的netTcp端点:

net.tcp://localhost:8551/MyServiceHost/Service/hostNetTcp
Run Code Online (Sandbox Code Playgroud)

现在,如果您定义了另一个协议,并且尚未在端点中定义绝对地址,则WCF将查找为该特定协议定义的基址,并使用基址生成端点.

如果WCF使用net.tcp基地址和netTcpBinding端点,如果你有两个tcp端点监听9000和9001会发生什么,你会在配置中放置什么来阻止冲突?

我认为在这个实例中最好在ypour端点中给出绝对地址:

<endpoint address="net.tcp://localhost:9000/MyServiceHost/Service"
                   binding="netTcpBinding"
                   contract="IMyService" />

<endpoint address="net.tcp://localhost:9001/MyServiceHost/Service"
                   binding="netTcpBinding"
                   contract="IMyService" />
Run Code Online (Sandbox Code Playgroud)

如前所述,当您提供绝对地址时,在生成端点地址时不会参考您的基址.

你可能想看看这个.