加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-17 00:03:14 所属栏目:大数据 来源:网络整理
导读:在其中一个WCF教程中,我看到了以下示例代码: Dim service as ...(a WCF service )try .. service.close()catch ex as Exception() ... service.abort()end try 这是确保即使在错误条件下也能释放资源(即连接)的正确方法吗? 我对这个模型好运: Dim service
在其中一个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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读