Null object reference error for SoapHeadersClientHook

Oct 10, 2013 at 4:47 PM
I am getting null object reference error at,

channel.Extensions.Find<SoapHeadersClientHook>().Headers[headerName] = value;

This is my client code

TestWCFClient.WebServiceInterfaceClient client = new TestWCFClient.WebServiceInterfaceClient();
        TestWCFClient.AuthenticationHeader header = new TestWCFClient.AuthenticationHeader(); 
        header.Username = "abcd";
        header.Hash = "ads";
        header.DateTime = Convert.ToDateTime("11/11/11");
        ClientSoapHeaderHelper.SetHeader(client.InnerChannel, "AuthenticationHeader", header);
        string result = client.HelloWorld(header, "hie");

Partial Class for ProxyClient

namespace TestApp.TestWCFClient
{
public partial class WebServiceInterfaceClient
{
    public AuthenticationHeader AuthHeader
    {
        get {
            return InnerChannel.GetHeader<AuthenticationHeader>("AuthenticationHeader");
        }
        set {
            InnerChannel.SetHeader("AuthenticationHeader", value);
        }
    }
}
}

Service Interface Code

  [SoapHeaders]
[ServiceContract]  
public interface WebServiceInterface
{
    [SoapHeader("AuthenticationHeader", typeof(AuthenticationHeader), Direction = SoapHeaderDirection.In)]
    [OperationContract]
    string HelloWorld(string inputValue);

}

Please suggest where i'm going wrong.

Regards,
Manoj