Hosting WCF service in IIS 7 (WAS) with net.tcp binding on TWO tcp ports
Asked Answered
C

3

5

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?

Chaos answered 12/9, 2009 at 21:3 Comment(0)
F
8

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

Felafel answered 13/9, 2009 at 6:52 Comment(2)
I read somewhere that baseAddresses is ignored in an iis enivornment.Pliable
I will agree with your comment and provide a link that says so. When it comes to IIS, base addresses are basically ignored, but the above example still holds because of the end point addresses being provided. They are implicitly used with the site binding info in IIS. msdn.microsoft.com/en-us/magazine/cc163412.aspxEdbert
Z
2

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>
Zeidman answered 13/6, 2010 at 13:19 Comment(1)
In .NET 4.0 this is fixed via <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>Parkerparkhurst
C
0

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

Chaos answered 14/9, 2009 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.