vb.net - service.close()与service.abort()-WCF示例

标签 vb.net wcf dispose

在WCF教程之一中,我看到了以下示例代码:

Dim service as ...(a WCF service )

try

   ..

   service.close()

catch ex as Exception()
  ... 

   service.abort()

end try

这是确保即使在错误情况下也可以释放资源(即连接)的正确方法吗?

最佳答案

我有这个模型的运气:

Dim service As New MyService()
Dim closed As Boolean = False
Try
    service.Open()
    If Not service.State = ServiceModel.CommunicationState.Opened Then
        ''Handle a not-opened state here
    End If
    service.MyMethod()
    service.Close()
    closed = true
Catch ex As Exception
    ''Handle errors here
Finally
    If Not closed Then
        service.Abort()
    End If
End Try
service = Nothing

关于vb.net - service.close()与service.abort()-WCF示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1155815/

相关文章:

c# - 在什么情况下应该使用 ESB 来管理传入的 WCF 服务请求?H

c# - 使用 RX 观察 WCF 服务调用

arrays - 尝试处理图像时应用程序崩溃

.net - 如何在实际绘画之前在光标处显示画笔?

.net - 在 .net 中指定一个实现 2 个接口(interface)的变量

WCF 架构,因此我可以使用回调并针对 AD 进行身份验证

asp.net - 在 WebSocketContext 中正确处理 WebSocket

c# - 是否可以区分具有相同完全限定名称的类型?

mysql - VB.Net 中 Mysql 中插入查询的语法错误

c# - 表单时未处理计时器