简体   繁体   English

WCF与PerCall,SessionMode.NotAllowed,回调?

[英]WCF with PerCall, SessionMode.NotAllowed, callback?

Hi, 你好

I have a Service that is using the following today 我有一项正在使用以下服务的服务

  • NETTCPBinding (WAS) NETTCPBinding(WAS)
  • Hosted In IIS7 托管在IIS7中
  • PerSession Service PerSession服务
  • SessionMode.Required SessionMode.Required
  • Callbacks 回呼
  • Singelton on service that holds all the client contexts Singelton拥有所有客户环境的服务

Say that I now need to change this to PerCall instanciated and SessionMode.NotAllowed , is this posible without loosing any of my key functionalitys above? 假设我现在需要将其更改为PerCall instanciated和SessionMode.NotAllowed ,这是否可行而又不会失去我上面的任何关键功能?

I have seen that TCP is a session bound protocoll and this means that I will have to use HTTP Binding witch is not as fast as TCP (XML 1.0 encoder instead of Binary encoder). 我已经看到TCP是一个会话绑定协议,这意味着我将不得不使用HTTP绑定,它的速度不如TCP(XML 1.0编码器而不是二进制编码器)快。 But Im still not sure if this will support for example callbacks? 但是我仍然不确定这是否支持例如回调?

PerCall and SessionMode.NotAllowed are "less" specific/restrictive than your current setup. 与当前设置相比, PerCallSessionMode.NotAllowed特定/限制性更小。 You should easily be able to transition to these settings so long as you realize the fundamental implication: no more state in between calls in your service instances. 只要您意识到基本的含义即可轻松过渡到这些设置:服务实例中的两次调用之间不再存在任何状态。

That said, I'm not sure I understand what you mean by "Singleton on service that holds all the client contexts". 就是说,我不确定我是否理解“拥有所有客户端上下文的服务式单一服务”的含义。 Can you elaborate? 你能详细说明吗? I think you mean your holding state within a singleton (static field?) in the service implementation. 我认为您的意思是您在服务实现中的单例(静态字段?)内的持有状态。 Accessing that from the PerCall instances will be fine, just remember you have to provide the locking around that state. PerCall实例访问它很好,只要记住您必须提供围绕该状态的锁定即可。 This is, for example, how you could maintain the list of callbacks. 例如,这就是如何维护回调列表。

Also, your understanding of TCP being session only is incorrect. 另外,您对仅作为会话的TCP的理解是不正确的。 Remember, HTTP is a protocol built on top of TCP. 请记住,HTTP是建立在TCP之上的协议。 Yes TCP sockets stay connected for some amount of time (keep alive) so they can be reused, but the messages you send over them can be completely unrelated to one another. 是的,TCP套接字保持连接一定时间(保持活动状态),以便可以重用它们,但是通过它们发送的消息可能彼此完全无关。 So if you stick with NetTcpBinding you'll be fine. 因此,如果您坚持使用NetTcpBinding,就可以了。 Likewise you can technically do sessions over the HTTP transport. 同样,您可以在技术上通过HTTP传输进行会话。 Also, if you switched to an HTTP based transport, you don't have to use text encoding. 另外,如果你切换到一个基于HTTP传输, 不必使用文本编码。 You can send binary content over the HTTP transport, it just requires setting up a custom binding that would look something like: 您可以通过HTTP传输发送二进制内容,只需要设置一个类似于以下内容的自定义绑定即可:

<bindings>
    <customBinding>
        <binding name="MyBinaryOverHttpBinding">
            <binaryMessageEncoding />
            <httpTransport />
        </binding>
    </customBinding>
</bindings>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM