Reputation: 5072
When I have many endpoints in my WCF service...
Would it be wise or possible to resuse the same port numbers for them.
Problem is when the service is deployed there are too many portnumbers to remeber for the different bindings used.
Upvotes: 2
Views: 4032
Reputation: 11074
If you have multiple endpoints in one service, perhaps with different contracts or bindings then you can use relative addressing using the base address as shown below.
<services>
<service name="CalculatorService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/CalculatorService"/>
<add baseAddress="net.tcp://localhost:8001/CalculatorService"/>
</baseAddresses>
</host>
<endpoint address="Mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="Basic" binding="basicHttpBinding" contract="IBasicCalculator" />
<endpoint address="Scientific" binding="netTcpBinding" contract="IScientificCalculator" />
</service>
</services>
Upvotes: 2
Reputation: 10885
It is certainly possible and I would say wise too - especially if you are hosting it as a web service on port 80, but even TCP too. It has always seemed overkill to me to have a port per service.
You will need a port per binding though (so pick a port to use for TCP, one for HTTP etc).
You can specify the same root address for your services like so (this is a JSON REST service but the binding is irrelevant) - notice the address attributes:
<system.serviceModel>
<services>
<service name="Demo.SampleService2Implementation">
<endpoint address="http://localhost:85/sample2"
behaviorConfiguration="json"
binding="webHttpBinding"
name="jsonEndpoint2"
contract="Demo.ISampleService2" />
</service>
<service name="Demo.SampleServiceImplementation">
<endpoint address="http://localhost:85/sample1"
behaviorConfiguration="json"
binding="webHttpBinding"
name="jsonEndpoint1"
contract="Demo.ISampleService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="json">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
And this is the client configuration:
<system.serviceModel>
<client>
<endpoint name="SampleServiceEndpoint"
address="http://localhost:85/sample1"
binding="webHttpBinding"
contract="Demo.ISampleService"
behaviorConfiguration="json">
</endpoint>
<endpoint name="SampleServiceEndpoint2"
address="http://localhost:85/sample2"
binding="webHttpBinding"
contract="Demo.ISampleService2"
behaviorConfiguration="json">
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="json">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Upvotes: 6