Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Special syntax on Using
Message
From
11/02/2014 15:11:40
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Special syntax on Using
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01594076
Message ID:
01594076
Views:
54
I am trying to adapt this method to use a Using syntax:
    ' Add the HTTP header
    Public Function AddHTTPHeader() As Boolean
        Dim lcName As String = ""
        Dim lcValue As String = ""
        Dim loObject(2) As Object
        Dim loHttpRequestMessageProperty As System.ServiceModel.Channels.HttpRequestMessageProperty = New System.ServiceModel.Channels.HttpRequestMessageProperty()

        ' Reset the values
        lSuccess = False

        ' If we have at least one HTTP header
        If oHTTPHeader.Count > 0 Then

            ' For each header
            For Each loObject In oHTTPHeader

                ' Initialization
                lcName = loObject(1)
                lcValue = loObject(2)

                ' Add the header
                loHttpRequestMessageProperty.Headers(lcName) = lcValue

            Next

            ' Set the header
            OperationContext.Current.OutgoingMessageProperties(System.ServiceModel.Channels.HttpRequestMessageProperty.Name) = _
             loHttpRequestMessageProperty

        End If

        lSuccess = True

        Return lSuccess
    End Function
So, I thought I would use this:
    ' Add the HTTP header
    Public Function AddHTTPHeader() As Boolean
        Dim lcName As String = ""
        Dim lcValue As String = ""
        Dim loObject(2) As Object

        ' Reset the values
        lSuccess = False

        Using loHttpRequestMessageProperty = New System.ServiceModel.Channels.HttpRequestMessageProperty()

            ' If we have at least one HTTP header
            If oHTTPHeader.Count > 0 Then

                ' For each header
                For Each loObject In oHTTPHeader

                    ' Initialization
                    lcName = loObject(1)
                    lcValue = loObject(2)

                    ' Add the header
                    loHttpRequestMessageProperty.Headers(lcName) = lcValue

                Next

                ' Set the header
                OperationContext.Current.OutgoingMessageProperties(System.ServiceModel.Channels.HttpRequestMessageProperty.Name) = _
                 loHttpRequestMessageProperty

            End If

        End Using

        lSuccess = True

        Return lSuccess
    End Function
The designer does not compliant but the run time does with a message:

"Unable to cast object of type 'System.ServiceModel.Channels.HttpRequestMessageProperty' to type 'System.IDisposable'."

I was pretty sure this was the same representation. Anyone knows what I am missing?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform