HttpRequestMessage with NetTcpBinding RRS feed

  • Question

  • Hi

    I am trying to pass some authorization data in the headers using behaviours and inspectors.

    On the client, it is:

     Public Function BeforeSendRequest(ByRef request As System.ServiceModel.Channels.Message, channel As System.ServiceModel.IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest
            Dim httpRequestMessage As HttpRequestMessageProperty = New HttpRequestMessageProperty()
                httpRequestMessage.Headers.Add(HttpRequestHeader.Authorization, "xyz")
                request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage)

            Return Nothing

        End Function

    On the server, it is:

     Public Function AfterReceiveRequest(ByRef request As Message, channel As IClientChannel, instanceContext As InstanceContext) As Object Implements IDispatchMessageInspector.AfterReceiveRequest

            Dim requestMessage As HttpRequestMessageProperty = TryCast(request.Properties("httpRequest"), HttpRequestMessageProperty)
            If request Is Nothing Then
                Throw New InvalidOperationException("Invalid request type.")
            End If
            Dim authHeader As String = requestMessage.Headers("Authorization")

            If String.IsNullOrEmpty(authHeader) OrElse Not Me.Authenticate(authHeader) Then
            End If

        End Function

    Above pieces of code work well on BasicHTTPBinding, but throw an error on the server when NetTCPBinding is used.

    The error is "A property with the name 'httpRequest' is not present" obtained in the first line of server function.

    Kindly advise what can be done about this.

    Best Regards


    Thursday, February 19, 2015 12:03 PM

All replies