WCF Service Base Address vs endpoint address
baseAddress
is just that, the base address for your endpoints (unless specified explicitly). So every <endpoint>
will inherit from <baseAddress>
(which is why they are usually ""
and "mex"
). e.g.
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:1337/" />
</baseAddresses>
</host>
...
<endpoint address="" contract="MyService.IMyContract" ... />
<endpoint address="mex" contract="IMetadataExchange" ... />
You now have two endpoints:
http://127.0.0.1:1337/
- service endpointhttp://127.0.0.1:1337/mex
- metadata endpoint
By exempting the <baseAddress>
you're requiring the <endpoints>
to both be fully qualified (including the mex (which is not)). e.g.
<host>
<baseAddresses/>
</host>
...
<endpoint address="net.tcp://127.0.0.1:1337/" contract="MyService.IMyContract" ... />
<endpoint address="http://127.0.0.1:1337/mex" contract="IMetadataExchange" ... />
You now have two different endpoints:
net.tcp://127.0.0.1:1337/
- service endpointhttp://127.0.0.1:1337/mex
- metadata endpoint
Simsons
Love to write programs . Still learning and trying to explain the code to my self and others.
Updated on April 03, 2020Comments
-
Simsons about 4 years
What's the difference between the following two cases:
Configuration 1:
<service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors"> <host> <baseAddresses> <add baseAddress="net.tcp://127.0.0.1:808/" /> </baseAddresses> </host> <endpoint address="service" binding="netTcpBinding" bindingConfiguration="MainBinding" bindingName="MainBinding" name="DefaultEndpoint" contract="WcfService1.IService1" /> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> </service>
Configuration 2:
<service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors"> <host> <baseAddresses> <add baseAddress="net.tcp://127.0.0.1:808/service" /> </baseAddresses> </host> <endpoint address="net.tcp://127.0.0.1:808/service" binding="netTcpBinding" bindingConfiguration="MainBinding" bindingName="MainBinding" name="DefaultEndpoint" contract="WcfService1.IService1" /> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" /> </service>
What I understand is In either case base address + endpoint address resolves to same absolute address
But why I get the error on Configuration 2 : "No end point is listening at net.tcp://127.0.0.1:808/
but Configuration 1 runs the service without any errors!!!Edit 1:
Working Config:
<host> <baseAddresses> <add baseAddress="net.tcp://127.0.0.1:808/" /> </baseAddresses> </host> <endpoint address="service" binding="netTcpBinding" bindingConfiguration="MainBinding" bindingName="MainBinding" name="DefaultEndpoint" contract="WcfService1.IService1" />
Non working Config:
<host> <!-- <baseAddresses> <add baseAddress="" /> </baseAddresses> --> </host> <endpoint address="net.tcp://127.0.0.1:808/service" binding="netTcpBinding" bindingConfiguration="MainBinding" bindingName="MainBinding" name="DefaultEndpoint" contract="WcfService1.IService1" /> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
In this case, I have removed base address and provided complete service address (with out .svc path) but get a socket time out error. What's wrong in this case? Does the end point address always need the complete address with .svc when base address is not defined? If so, what could be the reason behind?
-
Simsons over 10 yearsThanks ,in my question, in both configuration 1 and 2 , if we append the base address and end point address , the final URI will look like net.tcp://127.0.0.1:808/service .Am I right ? Or , will the base address will look like: net.tcp://127.0.0.1:808/service/net.tcp://127.0.0.1:808/service (appending twice)
-
Brad Christie over 10 yearsOnly when an absolute uri is specified does it ignore
baseAddress
(so,net.tcp://
,http://
, etc. would be a fully-qualified uri). Otherwise it's essentially appended to the baseAddress (which means your mex, in your second example, becomesnet.tcp://127.0.0.1:808/service/mex
, but the service remainsnet.tcp://127.0.0.1:808/service
) -
Simsons over 10 yearsBrad, Edited the question. Just confused , where am I wrong with wcf expectations. If you could have a look on this please