Adding Headers to SOAP Messages
For different effects (routing for example) it is necessary to add to the SOAP messages managed by WCF services a customized header (header) with information, in this way information can be sent between the clients and the services without it being necessary to modify the content of the service (data). A quick reminder of how to do it using code in WCF 3.5.
ServicioFuncionario.ServicioFuncionarioClient sv = new ServicioFuncionario.ServicioFuncionarioClient(); using (new OperationContextScope(sv.InnerChannel)) { MessageHeader headerLocal = MessageHeader.CreateHeader("Key", "http://serviciosproduccionCP", "HostCP"); OperationContext.Current.OutgoingMessageHeaders.Add(headerLocal); MessageHeader headerBogota = MessageHeader.CreateHeader("Key", "http://serviciosproduccionBogota", "HostBogota"); OperationContext.Current.OutgoingMessageHeaders.Add(headerBogota); resultado = sv.FuncionarioLogin(login, passWord); } sv.Close();
This code adds two headers to the funcionarioLogin request, the value HostCP and HostBogota is the one we are interested in adding to the messages, with that information the service could carry out different processes like routing, logging, error handling, backup among others.
Note1: in WCF 4.0 you can use the header tag in the service configuration file.
Note2: The protocol used in the communication must have support for header management in the SOAP message.
Juan Peláez
3Metas Corp
Need Expert Help?
Let's discuss how I can help with your technical challenges
Schedule a Consultation