在 IIS 7 (WAS) 中托管 WCF 服务,并在两个 tcp 端口上绑定 net.tcp

发布于 2024-08-05 03:35:17 字数 190 浏览 4 评论 0原文

默认情况下,IIS 7 网站具有带有“808:”绑定信息字符串的 net.tcp 绑定。如果我添加另一个带有“xxx:”的 net.tcp 绑定,则会发生异常:

此集合已包含具有方案 net.tcp 的地址。该集合中的每个方案最多可以有一个地址。 参数名称:item

我该如何解决这个问题并在两个端口监听我的服务?

By default IIS 7 Web site has net.tcp binding with "808:" binding information string. If i add another net.tcp binding with "xxx:" exception occurs:

This collection already contains an address with scheme net.tcp. There can be at most one address per scheme in this collection.
Parameter name: item

How can i solve this problem and listen my service at TWO ports?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九命猫 2024-08-12 03:35:17

基本上,在您的服务中,您应该能够在任意数量的端口上定义任意数量的服务端点。

有两种方法可以执行此操作:

  • 在服务端点中定义基地址和相对地址
  • 在每个端点中定义完整地址

如果您选择选项#1,您将有这样的内容:

<service name="YourService">
  <host>
    <baseAddresses>
      <add baseAddress="net.tcp://YourServer:5151/Services" />
    </baseAddresses>
  </host>
  <endpoint name="endpoint1"
            address="Service1"
            binding="netTcpBinding"
            contract="IYourService" />
  <endpoint name="endpoint2"
            address="Service2"
            binding="netTcpBinding"
            contract="IYourService" />
</service>

所以在这种情况下,同一个合约有两个服务端点,它们将监听 URL

net.tcp://YourServer:5151/Services/Service1

,并且

net.tcp://YourServer:5151/Services/Service2

您可以有多个服务端点,但只能有一个基地址。

另一种选择是不指定基地址并直接在端点中指定完整服务地址:

<service name="YourService">
  <endpoint name="endpoint1"
            address="net.tcp://YourServer:5151/Services/Service1"
            binding="netTcpBinding"
            contract="IYourService" />
  <endpoint name="endpoint2"
            address="net.tcp://YourServer:6868/Services/Service2"
            binding="netTcpBinding"
            contract="IYourService" />
</service>

在这种情况下,由于您在端点中定义整个地址,因此您可以选择两个不同的 TCP 端口,每个端点一个。这应该没有任何问题。您在两个单独的端口上有两个单独的端点,它们在后台侦听并由同一服务类提供服务。

马克

Basically, in your service, you should be able to define any number of service endpoints on any number of ports.

There's two ways to do this:

  • define a base address and a relative address in your service endpoint
  • define the full address in each endpoint

If you do option #1, you'll have something like this:

<service name="YourService">
  <host>
    <baseAddresses>
      <add baseAddress="net.tcp://YourServer:5151/Services" />
    </baseAddresses>
  </host>
  <endpoint name="endpoint1"
            address="Service1"
            binding="netTcpBinding"
            contract="IYourService" />
  <endpoint name="endpoint2"
            address="Service2"
            binding="netTcpBinding"
            contract="IYourService" />
</service>

So in this case, you have two service endpoints for the same contract, and they'll be listening on URLs

net.tcp://YourServer:5151/Services/Service1

and

net.tcp://YourServer:5151/Services/Service2

You can have mulitple service endpoints, but only one base address.

The other option is to specify no base addresses and specify your full service address in the endpoint directly:

<service name="YourService">
  <endpoint name="endpoint1"
            address="net.tcp://YourServer:5151/Services/Service1"
            binding="netTcpBinding"
            contract="IYourService" />
  <endpoint name="endpoint2"
            address="net.tcp://YourServer:6868/Services/Service2"
            binding="netTcpBinding"
            contract="IYourService" />
</service>

In this case, since you're defining the whole address in the endpoint, you can pick two different TCP ports, one for each endpoint. This should work with no problem at all. You have two separate endpoints on two separate ports, both listening and being serviced by the same service class in the background.

Marc

那小子欠揍 2024-08-12 03:35:17

前几天,我试图将 WCF 服务部署到我的一台 Web 服务器上,但遇到了问题。我不断收到以下错误消息:p>

该集合已包含一个带有 http 方案的地址。此集合中每个方案最多可以有一个地址。参数名称:item

该问题并未发生在我的本地计算机上,而是发生在 Web 服务器上,这使得找出导致该问题的原因有点困难。它发生在服务器上,因为我的 Web 服务器位于共享托管环境中,在这种情况下,WCF 服务还需要知道主机标头。为此,我导航到 web.config 并添加了以下内容:

<serviceHostingEnvironment>
<baseAddressPrefixFilters>    
    <add prefix=http://MyHostHeader />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>

I was trying to deply a WCF service to one of my web servers the other day and ran into a problem. I kept getting the following error message:p>

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.Parameter name: item

The problem didn't happen on my local machine but did on the web server making it a little difficult to figure out what was causing it. It happened on the server because my web server is in a shared hosting environment in which case the WCF service also needs to know the host header. To do this I navigated to in the web.config and added the following:

<serviceHostingEnvironment>
<baseAddressPrefixFilters>    
    <add prefix=http://MyHostHeader />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
鱼忆七猫命九 2024-08-12 03:35:17

又是我。

这适用于自主机

 <baseAddresses>
            <add baseAddress="net.tcp://localhost" />
            <add baseAddress="net.tcp://localhost:12345" />
 </baseAddresses>

,但使用 IIS7+WAS 会导致异常

无法连接到 net.tcp://localhost:12345/game2.svc。连接尝试持续的时间跨度为 00:00:02.0936160。 TCP错误代码10061:无法建立连接,因为目标机器主动拒绝127.0.0.1:12345。

问题是关于IIS托管环境

Its me again.

This works with self host

 <baseAddresses>
            <add baseAddress="net.tcp://localhost" />
            <add baseAddress="net.tcp://localhost:12345" />
 </baseAddresses>

but with IIS7+WAS cause exception

Could not connect to net.tcp://localhost:12345/game2.svc. The connection attempt lasted for a time span of 00:00:02.0936160. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:12345.

The question was about IIS hosting environment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文