tags:

views:

422

answers:

0

To consume WCF services, we dynamically create channels using the following pattern.

    Dim subscriptionsService As ISubscriptionsService = ProfileChannelFactory.Create(Of ISubscriptionsService)()
    Dim result As Subscription() = Nothing
    Try
        result = subscriptionsService.GetSubscriptions(New GetSubscriptionsRequest()).Subscriptions
    Catch ex As Exception
        HandleServiceException(ex)
    Finally
        Try
            DirectCast(subscriptionsService, ICommunicationObject).Close()
        Catch ex As Exception
            DirectCast(subscriptionsService, ICommunicationObject).Abort()
        End Try
    End Try

    Return result

The channel factory is implemented inside the factory class as a static member -- we create it once and never close it. Just wondering if we have any potential resource leaks with this pattern.

Thanks!