【发布时间】:2014-08-22 12:07:43
【问题描述】:
我创建了一个 WCF 服务,其中包含许多消费者使用的 basicHttpBinding。现在,我需要实现一个基于会话的跟踪机制,以在多个呼叫中保持第 3 方连接处于活动状态。
我了解 basicHttpBinding 不支持会话状态,但我想让服务在“每个会话”模式下运行,而无需创建新的 wsHttpBinding 并破坏我当前的消费者。
有没有一种简单的方法来实现“每会话”模式而不会破坏我当前的消费者?
【问题讨论】:
我创建了一个 WCF 服务,其中包含许多消费者使用的 basicHttpBinding。现在,我需要实现一个基于会话的跟踪机制,以在多个呼叫中保持第 3 方连接处于活动状态。
我了解 basicHttpBinding 不支持会话状态,但我想让服务在“每个会话”模式下运行,而无需创建新的 wsHttpBinding 并破坏我当前的消费者。
有没有一种简单的方法来实现“每会话”模式而不会破坏我当前的消费者?
【问题讨论】:
您可以在 app.config 中创建一个新的 wsHttpBinding 并为当前消费者维护现有的 basicHttpBinding。您只需为每个绑定添加一个服务端点到 app.config。您可能希望为 wsHttpBinding 使用不同的地址。
<service name="MyService">
<endpoint address="http://domain.com/MyService.svc" binding="basichHttpBinding" bindingConfiguration="basicHttpBindingConfig" Contract="MyService"/>
<endpoint address="https://domain.com/MyService.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfig" Contract="MyService"/>
</service>
现在,使用 http 端点的任何人都将使用 basicHttpBinding,而使用 https 端点的任何人都将使用 wsHttpBinding。
这种易于配置是 WCF 的美妙之处。
【讨论】: