Click here to Skip to main content
13,300,654 members (50,392 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 10 Apr 2012

How to add headers in a WF service client and how to get Headers value in WF service

, 10 Apr 2012
Rate this:
Please Sign up or sign in to vote.
Add headers in WF service client and get headers value in WF service.

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>(
        //Assigning Name and NameSpace to the message header value at client side
        System.ServiceModel.Channels.MessageHeader header = mess.GetUntypedHeader("UserID", "ns");
        //Adding message header with OperationContext which will be received at the server side
        varx = proxy.GetData(2);

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:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Anuj Banka
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionThank you.. Pin
Robert den Boer14-Aug-14 17:52
professionalRobert den Boer14-Aug-14 17:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 10 Apr 2012
Article Copyright 2012 by Anuj Banka
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid