简体   繁体   English

WCF 服务基地址与端点地址

[英]WCF Service Base Address vs endpoint address

What's the difference between the following two cases:以下两种情况有什么区别:

Configuration 1:配置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:配置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/但是为什么我在配置 2上收到错误: “没有端点正在侦听 net.tcp://127.0.0.1:808/
but Configuration 1 runs the service without any errors !!!但是配置 1运行服务没有任何错误!!!

Edit 1:编辑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.在这种情况下,我已经删除了基地址并提供了完整的服务地址(没有 .svc 路径),但出现套接字超时错误。 What's wrong in this case?在这种情况下有什么问题? Does the end point address always need the complete address with .svc when base address is not defined?当未定义基地址时,端点地址是否总是需要带有 .svc 的完整地址? If so, what could be the reason behind?如果是这样,背后的原因可能是什么?

baseAddress is just that, the base address for your endpoints (unless specified explicitly). baseAddress就是端点的基地址(除非明确指定)。 So every <endpoint> will inherit from <baseAddress> (which is why they are usually "" and "mex" ).所以每个<endpoint>都将从<baseAddress>继承(这就是为什么它们通常是"""mex" )。 eg例如

<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/ - 服务端点
  • http://127.0.0.1:1337/mex - metadata endpoint http://127.0.0.1:1337/mex - 元数据端点

By exempting the <baseAddress> you're requiring the <endpoints> to both be fully qualified (including the mex (which is not)).通过免除<baseAddress>您要求<endpoints>都是完全合格的(包括 mex(不是))。 eg例如

<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 net.tcp://127.0.0.1:1337/ - 服务端点
  • http://127.0.0.1:1337/mex - metadata endpoint http://127.0.0.1:1337/mex - 元数据端点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM