Add SOAPHeader to each request

647 Views Asked by At

I'm very new about this topic, so I'm sorry if my problem explanation will be not very clear.

I'm using Visual Studio 2019 c#, and I'm creating a sw that has to connect to a server to read some data.

I add a WFC Web service using the integrated tool in VS and it creates a connected service that inhertis from System.ServiceModel.ClientBase and XXXProxy classes.

To connect to the server I need the credentials and to add a SOAPHeader to the messages.

How can I add this SOAPHeader?

I have the corresponding java code and for each request a SOAPHeader is created with SOAPHeaderElement.

Can anyone give me an help?

Thanks a lot

1

There are 1 best solutions below

0
On

You can try the message inspector, on the client side, intercept SOAP messages by implementing the IClientMessageInspector interface. On the server side, intercept SOAP messages by implementing the IDispatchMessageInspector interface.

You can also use OperationContextScope to create new contexts in client applications to add custom headers to outgoing messages.

These are some usefull links:
Adding SOAP Header to request
Adding Http Header in an existing WCF SOAP Service is not working
How to add custom soap headers in wcf?