In the service side we will get the header with the same name and namespace that we have created the header in the client side using IncomingMessageHeaders and do our service operation .
Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports System.Runtime.Serialization
Imports System.ServiceModel.Channels
<ServiceContract(Namespace:="")> _
<AspNetCompatibilityRequirements
(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class PersonService
<OperationContract()> _
Public Sub DoWork()
' Add your operation implementation here
End Sub
' Add more operations here and mark them with <OperationContract()>
<OperationContract()> _
Public Function GetPersonData() As String
Dim PersonObj As New Person
Dim messageHeadersElementIncoming As MessageHeaders = OperationContext.Current.IncomingMessageHeaders
Try
Dim IsAuth As Integer
IsAuth = messageHeadersElementIncoming.FindHeader("Authentication", "")
If IsAuth > -1 Then
PersonObj = messageHeadersElementIncoming.GetHeader(Of [Person])("Authentication", "")
If PersonObj.UserName = "Soumyap" And PersonObj.Password = "Mindfire" Then
Return "Hello"
End If
End If
Catch ex As Exception
Return Nothing
End Try
Return Nothing
End Function
End Class
<DataContract()> _
Public Class Person
Private UserNameStr As String
Private PasswordStr As String
<DataMember()> _
Public Property UserName() As String
Get
Return UserNameStr
End Get
Set(ByVal value As String)
UserNameStr = value
End Set
End Property
<DataMember()> _
Public Property Password() As String
Get
Return PasswordStr
End Get
Set(ByVal value As String)
PasswordStr = value
End Set
End Property
End Class