Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Special syntax on Using
Message
From
11/02/2014 15:18:31
 
 
To
11/02/2014 15:11:40
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
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:
01594079
Views:
28
>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?

HttpRequestMessageProperty (http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httprequestmessageproperty%28v=vs.110%29.aspx) doesn't implement IDisposable. You can only use the "using" statement on classes that implement that interface.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform