Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Special syntax on Using
Message
 
 
À
11/02/2014 15:11:40
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01594076
Message ID:
01594078
Vues:
38
>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?

Based on the error message only this class doesn't implement IDisposable interface which means you can not wrap it into using statement.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform