For adding headers in a client application, add a service reference in the client application.
And write the following code for adding headers:
using (WFServiceRef.ServiceClientproxy = new WFServiceRef.ServiceClient())
{
using (newSystem.ServiceModel.OperationContextScope(proxy.InnerChannel))
{
MessageHeader<string> mess = newMessageHeader<string>(
System.Security.Principal.WindowsIdentity.GetCurrent().Name);
System.ServiceModel.Channels.MessageHeader header = mess.GetUntypedHeader("UserID", "ns");
OperationContext.Current.OutgoingMessageHeaders.Add(header);
varx = proxy.GetData(2);
Response.Write(x);
}
}
And in the WF service, we will create a class and call the function of the class in the WF service using InvokeMethod
.
And the class will look like this:
using System.Web;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace WFSERVICE
{
public class TestClass
{
public void SomeMethod()
{
EndpointAddress clientAddress = OperationContext.Current.Channel.RemoteAddress;
MessageHeaders headers = OperationContext.Current.RequestContext.RequestMessage.Headers;
var userID = OperationContext.Current.IncomingMessageHeaders.GetHeader<string>("UserID","ns");
}
}
}
And the workflow will look like this: