Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Service Base Address vs endpoint address

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?

like image 682
Simsons Avatar asked Sep 10 '13 13:09

Simsons


1 Answers

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 endpoint
  • http://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 endpoint
  • http://127.0.0.1:1337/mex - metadata endpoint
like image 74
Brad Christie Avatar answered Sep 21 '22 17:09

Brad Christie