gpt4 book ai didi

WCF 多重绑定(bind)端口号

转载 作者:行者123 更新时间:2023-12-05 09:24:52 24 4
gpt4 key购买 nike

当我的 WCF 服务中有许多端点时...

为它们重新使用相同的端口号是否明智或可能。

问题是部署服务时有太多端口号无法记住使用的不同绑定(bind)。

最佳答案

这当然是可能的,我也认为这是明智的 - 特别是如果您将其作为 Web 服务托管在端口 80 上,甚至 TCP 也是如此。对我来说,每个服务都有一个端口似乎有点过分了。

虽然每个绑定(bind)都需要一个端口(因此选择一个用于 TCP 的端口,一个用于 HTTP 等)。

您可以像这样为您的服务指定相同的根地址(这是一个 JSON REST 服务,但绑定(bind)无关紧要)——注意地址属性:

<system.serviceModel>
<services>
<service name="Demo.SampleService2Implementation">
<endpoint address="http://localhost:85/sample2"
behaviorConfiguration="json"
binding="webHttpBinding"
name="jsonEndpoint2"
contract="Demo.ISampleService2" />
</service>

<service name="Demo.SampleServiceImplementation">
<endpoint address="http://localhost:85/sample1"
behaviorConfiguration="json"
binding="webHttpBinding"
name="jsonEndpoint1"
contract="Demo.ISampleService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="json">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>

这是客户端配置:

<system.serviceModel>
<client>
<endpoint name="SampleServiceEndpoint"
address="http://localhost:85/sample1"
binding="webHttpBinding"
contract="Demo.ISampleService"
behaviorConfiguration="json">
</endpoint>

<endpoint name="SampleServiceEndpoint2"
address="http://localhost:85/sample2"
binding="webHttpBinding"
contract="Demo.ISampleService2"
behaviorConfiguration="json">
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="json">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>

关于WCF 多重绑定(bind)端口号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8234855/

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