Per Enzo,
in primo luogo InteropToolkit vuole il framework 2.0 ma, oltre ad esso, la parte vb.net è stat destinata al framework 4.5.
Io ho usato vb.net 13 con cui non funziona il plugin dell?interop Toolkit che consentirebbe di produrre automaticamente la classe wrapper; ma se guardi gli esempi, la classe wrapper la puoi fare da solo.
In secondo luogo ti posto i sorgenti delle due classi per come io le ho tradotte da C#, con in più una modifica per parametrizzare la SOAPAction.
(A titolo di informazione la prossima scadenza è in parte saltata e in parte allegerita)
Imports System.ServiceModel.Dispatcher
Imports System.Text
Imports System.ServiceModel.Channels
Public Class BasicAuthenticationInspector
Implements IClientMessageInspector
Private msauthorization As String
Private msSOAPAction As String
Public Sub New(ByVal UserName As String, ByVal Password As String, ByVal SOAPAction As String)
msauthorization = "Basic " & Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", UserName, Password)))
msSOAPAction = SOAPAction
End Sub
Public Sub AfterReceiveReply(ByRef reply As System.ServiceModel.Channels.Message, ByVal correlationState As Object) Implements System.ServiceModel.Dispatcher.IClientMessageInspector.AfterReceiveReply
Exit Sub
End Sub
Public Function BeforeSendRequest(ByRef request As System.ServiceModel.Channels.Message, ByVal channel As System.ServiceModel.IClientChannel) As Object Implements System.ServiceModel.Dispatcher.IClientMessageInspector.BeforeSendRequest
' ottengo un riferimento alla richiesta http sottostante
Dim richiestaHttp As HttpRequestMessageProperty
richiestaHttp = CType(request.Properties.Values(1), HttpRequestMessageProperty)
If Not IsNothing(richiestaHttp) Then
' richiestaHttp.Headers.Add("SOAPAction", msSOAPAction)
richiestaHttp.Headers.Add("Authorization", msauthorization)
Else
''non c'era? La creiamo noi.
richiestaHttp = New HttpRequestMessageProperty
richiestaHttp.Headers.Add("Authorization", msauthorization)
'request.Properties.Add(HttpRequestMessageProperty.Name, richiestaHttp)
' richiestaHttp.Headers.Add("SOAPAction", msSOAPAction)
request.Properties.Add(HttpRequestMessageProperty.Name, richiestaHttp)
End If
BeforeSendRequest = request
End Function
End Class
Imports System.ServiceModel
Imports System.Text
Imports System.ServiceModel.Description
Public Class BasicAuthenticationBehavior
Implements IEndpointBehavior
Private msUserName As String
Private msPassword As String
Private msSOAPAction As String
Public Sub ApplyClientBehavior(ByVal endpoint As ServiceEndpoint, ByVal clientRuntime As Dispatcher.ClientRuntime) Implements IEndpointBehavior.ApplyClientBehavior
' aggiungo un'istanza dell'inspector
clientRuntime.MessageInspectors.Add(New BasicAuthenticationInspector(msUserName, msPassword, msSOAPAction))
End Sub
Public Sub New(ByVal UserName As String, ByVal Password As String, ByVal SOAPAction As String)
' raccolgo user e password che passerò poi al costruttore di IClientMessageInspector
msUserName = UserName
msPassword = Password
msSOAPAction = SOAPAction
End Sub
Public Sub AddBindingParameters(ByVal endpoint As ServiceEndpoint, ByVal bindingParameters As System.ServiceModel.Channels.BindingParameterCollection) Implements IEndpointBehavior.AddBindingParameters
Exit Sub
End Sub
Public Sub ApplyDispatchBehavior(ByVal endpoint As ServiceEndpoint, ByVal endpointDispatcher As Dispatcher.EndpointDispatcher) Implements IEndpointBehavior.ApplyDispatchBehavior
Exit Sub
End Sub
Public Sub Validate(ByVal endpoint As ServiceEndpoint) Implements IEndpointBehavior.Validate
Exit Sub
End Sub
End Class