WCF服务的基址VS端点地址

编程入门 行业动态 更新时间:2024-10-27 21:15:03
本文介绍了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="127.0.0.1:1337/" /> </baseaddresses> ... <endpoint address="" contract="MyService.IMyContract" ... /> <endpoint address="mex" contract="IMetadataExchange" ... />

您现在有两个端点:

  • 127.0.0.1:1337/ - 服务端点
  • 127.0.0.1:1337/mex - 元数据终结
  • 127.0.0.1:1337/ - service endpoint
  • 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="127.0.0.1:1337/mex" contract="IMetadataExchange" ... />

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

You now have two different endpoints:

  • 的net.tcp://127.0.0.1:1337 / - 服务端点
  • 127.0.0.1:1337/mex - 元数据终结
  • net.tcp://127.0.0.1:1337/ - service endpoint
  • 127.0.0.1:1337/mex - metadata endpoint

更多推荐

WCF服务的基址VS端点地址

本文发布于:2023-11-07 09:10:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566062.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:基址   地址   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!