简体   繁体   English

中止WCF连接

[英]Abort a WCF connection

Is there a way to stop a remote connection? 有没有办法停止远程连接?

In more detail if a WCF connection is created using the ChannelFactory 更详细地讲,是否使用ChannelFactory创建了WCF连接

var aChannelFactory = new ChannelFactory<ISomeService>(aBinding, aEndpoint);

and the connection is used via GSM, it makes sense to enlarge timeouts so that 并且通过GSM使用该连接,因此可以扩大超时时间,以便

aChannelFactory.CreateChannel();

has the possibility to connect to the remote site. 可以连接到远程站点。

Now the problem is that a user may have the wish to stop the creation of a connection (Abort a getting connencted window, only use offline part of a programm). 现在的问题是,用户可能希望停止创建连接(中止连接窗口,仅使用程序的脱机部分)。

But how is this possible? 但这怎么可能呢?

The CreateChannel-call is synchronous. CreateChannel调用是同步的。

Even if it is wrapped in a thread, nowadays Thread.Abort should not be used. 即使将其包装在线程中,如今也不应使用Thread.Abort。

Is there any way to stop the creation of a channel automatically? 有什么方法可以自动停止创建频道吗?

Or must it be "faked" to a user, so that the connection still is running until its timeout (or success) even is user decided to work temporarely offline? 还是必须将其“伪造”给用户,以使连接仍在运行直到超时(或成功),甚至用户决定暂时脱机工作?

正如Grant Thomas所说,没有必要中止连接。

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

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