7

以下两种情况有什么区别:

配置一:

<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>

配置二:

<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>

我的理解是在任何一种情况下,基地址+端点地址都解析为相同的绝对地址

但是为什么我在配置 2上收到错误:“没有端点正在监听 net.tcp://127.0.0.1:808/
配置 1 运行服务没有任何错误!!!

编辑1:

工作配置:

<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" />

非工作配置:

<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" />

在这种情况下,我删除了基地址并提供了完整的服务地址(没有 .svc 路径),但收到了套接字超时错误。在这种情况下有什么问题?未定义基地址时,端点地址是否总是需要带有 .svc 的完整地址?如果是这样,背后的原因可能是什么?

4

1 回答 1

20

baseAddress就是这样,您的端点的基地址(除非明确指定)。所以每个<endpoint>人都会继承自<baseAddress>(这就是为什么他们通常是""and "mex")。例如

<host>
   <baseAddresses>
     <add baseAddress="http://127.0.0.1:1337/" />
   </baseAddresses>
</host>
...
<endpoint address="" contract="MyService.IMyContract" ... />
<endpoint address="mex" contract="IMetadataExchange" ... />

您现在有两个端点:

  • http://127.0.0.1:1337/- 服务端点
  • http://127.0.0.1:1337/mex- 元数据端点

通过豁免<baseAddress>您要求<endpoints>两者都完全合格(包括mex(不是))。例如

<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" ... />

您现在有两个不同的端点:

  • net.tcp://127.0.0.1:1337/- 服务端点
  • http://127.0.0.1:1337/mex- 元数据端点
于 2013-09-10T13:55:07.037 回答