Answer the question
In order to leave comments, you need to log in
How to set custom headers for every SOAP(WCF) request?
Connected to the project WSLD'ku through the Project-> Connect the reference to service.
Objects were generated, everything is fine. It’s not great that the SOAP service I’m accessing does not support standard authorization through an indication of the Creditials object, but asks to request the Login method, returns a token, and I must register this token as a header for each request that I will send subsequently.
I would appreciate any hint on how to do this!
Answer the question
In order to leave comments, you need to log in
He asked, he answered ...
And so, the mechanism is as follows:
public object BeforeSendRequest( ref Message request, IClientChannel channel ) {
MessageHeader header = MessageHeader.CreateHeader( "authenticate", "NS", "value" );
request.Headers.Add( header );
Console.WriteLine( "BeforeSendRequest" );
return null;
}
public void ApplyClientBehavior( ServiceEndpoint endpoint, ClientRuntime clientRuntime ) {
clientRuntime.ClientMessageInspectors.Add( new ClientMessageInspector() );
}
client = new ApiSoapPortClient();
client.Endpoint.EndpointBehaviors.Add( new CustomBehavior() );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question