简体   繁体   English

即使仅调用单向方法,WCF服务实例也不会关闭

[英]WCF service instance will not close despite only calling oneway method

I have a WCF service running inside a windows service on a remote machine. 我有一个WCF服务在远程计算机上的Windows服务中运行。 In the WCF service's contract, I have a method that takes a long time to run set up as 在WCF服务的合同中,我有一种方法需要花费很长时间来运行

[OperationContract(IsOneWay = true)]
void Update(myClass[] stuff);

Everything works fine, the method gets called, I can see what it needs to do start getting done. 一切正常,方法被调用,我可以看到它需要做的事情开始完成。

The problem is when I go to close the instance of the WCF service in my code, it times out and I get: 问题是当我在代码中关闭WCF服务的实例时,它超时并得到:

The socket connection was aborted. 套接字连接已中止。 This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. 这可能是由于处理您的消息时出错,远程主机超出了接收超时或潜在的网络资源问题引起的。 Local socket timeout was '00:02:00'. 本地套接字超时为“ 00:02:00”。

I thought the one way contract allowed me to fire and move on. 我以为单向合同允许我开除并继续前进。 Is there something I am missing? 我有什么想念的吗? If not are there workarounds for this? 如果没有,解决方法呢?

The ServiceContract attribute on your service's interface definition defaults the SessionMode property to SessionMode.Allowed, ie, 服务接口定义上的ServiceContract属性默认将SessionMode属性设置为SessionMode.Allowed,即

[ServiceContract(SessionMode = SessionMode.Allowed)]
public interface IMyContract
{
    [OperationContract(IsOneWay = true)]
    void Update(myClass[] stuff);
}

According to Juval Lowy's Programming WCF Services , 根据Juval Lowy的《 编程WCF服务》

...when the SessionMode property is configured with SessionMode.Allowed, it merely allows transport sessions, but does not enforce it. ...当使用SessionMode配置SessionMode属性时。允许,它仅允许传输会话,但不强制执行。 The exact resulting behavior is a product of the service configuration and the binding used. 产生的确切行为是服务配置和所使用的绑定的乘积。

Thus, if you are using the WSHttpBinding with security or reliable messaging, the NetTcpBinding, or the NetNamedPipeBinding, then the service will behave as a per-session service. 因此,如果您将WSHttpBinding与安全性或可靠消息传递,NetTcpBinding或NetNamedPipeBinding一起使用,则该服务将充当每个会话的服务。 This simply means that as long as the client proxy has not been closed, a session will still be in place between the service and the client. 这仅表示只要客户端代理尚未关闭,服务和客户端之间的会话仍将存在。 By closing the client proxy as suggested by Shiraz should fix this. 如Shiraz建议,关闭客户端代理即可解决此问题。

Juval's book also says this with regard to one-way operations: Juval的书还针对单向操作说明了这一点:

If the number queued messages has exceeded the queue's capacity, then the client will block, even when issuing a one-way call. 如果排队的消息数已超过队列的容量,则即使发出单向呼叫,客户端也将阻塞。 However, one the call is queued, the client is unblocked and can continue executing, while the service processes the operation in the background. 但是,一个呼叫被排队,客户端被解除阻塞并且可以继续执行,而服务则在后台处理操作。

So while one-way operations do allow for fire-and-forget operation, you can still run into cases where your client may block. 因此,尽管单向操作确实允许“一劳永逸”操作,但是您仍然可能遇到客户端可能阻塞的情况。

Your "Update" is a method on the service. 您的“更新”是服务的一种方法。

When you open the wcf client, a connection to the service remains open until you call Close (or Abort). 打开wcf客户端时,与服务的连接将保持打开状态,直到您调用“关闭”(或“中止”)。

You are probably not calling close, and it is therefore remaining open until it timesout. 您可能没有调用close,因此它一直保持打开状态直到超时。

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

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