如何在 WCF 中设置多个后备端点
如何设置回退端点。我在 conifg 文件中指定了多个端点,如下所示。如果服务无法访问,那么我的客户应该检查列表中指定的下一个地址。
客户端配置文件:
<client>
<endpoint address="http://192.168.1.4/SampleAppWeb/Services/SampleAppService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleAppService"
contract="SampleAppServiceReference.ISampleAppService" name="BasicHttpBinding_ISampleAppService" />
<endpoint address="http://172.168.12.121/SampleAppWeb/Services/SampleAppService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleAppService"
contract="SampleAppServiceReference.ISampleAppService" name="BasicHttpBinding_ISampleAppService1" />
<endpoint address="http://127.0.0.1/Services/SampleAppWeb/SampleAppService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleAppService"
contract="SampleAppServiceReference.ISampleAppService" name="BasicHttpBinding_ISampleAppService2" />
<endpoint address="http://172.168.111.115/Services/SampleAppWeb/SampleAppService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleAppService"
contract="SampleAppServiceReference.ISampleAppService" name="BasicHttpBinding_ISampleAppService3" />
</client>
代码隐藏:
var pass = new SampleAppServiceReference.SampleAppServiceClient("BasicHttpBinding_ISampleAppService3");
How to set fall-back endpoint. I'm having more than one endpoint specified in the conifg file like follows. If the service was not accessible, then my client should check the next address specified in the list.
Client Configuration File:
<client>
<endpoint address="http://192.168.1.4/SampleAppWeb/Services/SampleAppService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleAppService"
contract="SampleAppServiceReference.ISampleAppService" name="BasicHttpBinding_ISampleAppService" />
<endpoint address="http://172.168.12.121/SampleAppWeb/Services/SampleAppService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleAppService"
contract="SampleAppServiceReference.ISampleAppService" name="BasicHttpBinding_ISampleAppService1" />
<endpoint address="http://127.0.0.1/Services/SampleAppWeb/SampleAppService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleAppService"
contract="SampleAppServiceReference.ISampleAppService" name="BasicHttpBinding_ISampleAppService2" />
<endpoint address="http://172.168.111.115/Services/SampleAppWeb/SampleAppService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleAppService"
contract="SampleAppServiceReference.ISampleAppService" name="BasicHttpBinding_ISampleAppService3" />
</client>
Code Behind:
var pass = new SampleAppServiceReference.SampleAppServiceClient("BasicHttpBinding_ISampleAppService3");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WCF 本身没有任何内置功能,但您可以轻松创建一个类来为您重试。下面的示例展示了一种这样的方式。请注意,如果您的绑定使用会话,您可能需要重新创建客户端(而不是简单地重用它),因为如果发生错误,其通道可能会出现故障。
WCF itself doesn't have any built-in feature for this, but you can easily create a class which will do the retrying for you. The example below shows one such way. Notice that if your binding uses session, you may need to recreate the client (instead of simply reusing it), as its channel will likely be faulted if an error happens.