gpt4 book ai didi

c# - WCF 服务基址与端点地址

转载 作者:太空狗 更新时间:2023-10-29 22:12:13 26 4
gpt4 key购买 nike

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

配置一:

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

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

但为什么我在 Configuration 2 上收到错误:“No end point is listening at 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 的完整地址?如果是这样,背后的原因可能是什么?

最佳答案

baseAddress就是这样,你的端点的基地址(除非明确指定)。所以每个 <endpoint>将从 <baseAddress> 继承(这就是为什么它们通常是 """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 - 元数据端点

关于c# - WCF 服务基址与端点地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18720810/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com