WCF服务的基址VS端点地址 [英] WCF Service Base Address vs endpoint address

查看:199
本文介绍了WCF服务的基址VS端点地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是以下两种情况的区别是:

What's the difference between the following two cases:

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

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

我的理解是在这两种情况下的基地址+端点地址解析为相同的绝对地址

但是,为什么我得到的配置2 错误:没有终点监听的net.tcp://127.0.0.1:808 /
配置1 运行服务没有任何错误的!

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

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

非工作配置:

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

在这种情况下,我已删除的基址,并提供完整的服务地址(与出.SVC路径)却得到了一个套接字超时错误。什么是错在这种情况下?是否终点地址总是需要在基址没有定义与.SVC完整的地址?如果是这样,这可能是背后的原因是什么?

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?

推荐答案

baseAddress 就是这样,基地址为端点(除非明确说明)。所以每&LT;端点&GT; 将继承&LT; baseAddress&GT; (这就是为什么他们通常MEX)。例如,

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.

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

您现在有两个端点:

  • http://127.0.0.1:1337/ - 服务端点
  • http://127.0.0.1:1337/mex - 元数据终结
  • http://127.0.0.1:1337/ - service endpoint
  • http://127.0.0.1:1337/mex - metadata endpoint

,免除&LT; baseAddress&GT; 你需要的&LT;端点&GT; 这两个是完全合格(包括MEX(不是))。例如,

By exempting the <baseAddress> you're requiring the <endpoints> to both be fully qualified (including the mex (which is not)). e.g.

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

这篇关于WCF服务的基址VS端点地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆