channel.Extensions.Find<SoapHeadersClientHook> null exception

Jan 27, 2010 at 9:40 AM
Edited Jan 27, 2010 at 9:57 AM

Hello,

I am receiving an error in ClientSoapHeaderHelper class's SetHeader method. At row :

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

It couldn't find any SoapHeadersClientHook, and there is a NULLReference Exception. What can cause this problem? My code is as follows :

 

usingSystem.ServiceModel;

 usingSystem.Web.Services.Protocols;

// NOTE: If you change the interface name "IRndWebService" here, you must also update the reference to "IRndWebService" in Web.config.

[

ServiceContract]
public interface IRndWebService{
[
OperationContract][SoapHeader("SecurityHeader", Direction = SoapHeaderDirection.In)]
string Test();
}

using System;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using WCFExtras.Soap;
using System.Web.Services.Protocols;
// NOTE: If you change the class name "RndWebService" here, you must also update the reference to "RndWebService" in Web.config. public class RndWebService : IRndWebService
{
public EtradeSoapHeader SecurityHeader { get; set; }
public string Test()
{
if (ExamineAuthority(SecurityHeader))return "alyor.";
return "Yetkisiz giri";
} 

 

private static bool ExamineAuthority(EtradeSoapHeader headerInfo)
{
string systemCode = "*******";
string userName = "******";
string password = "********";
if (headerInfo.SYSTEM_CODE == systemCode && headerInfo.USERNAME == userName && headerInfo.PASSWORD == password)
return true;
return false;
}
}
public class EtradeSoapHeader : SoapHeader
{
public string PASSWORD { get; set; } public string SYSTEM_CODE { get; set; } public string USERNAME { get; set; }

}

My client code is as follows : 

 

        EtradeSoapHeader header = new EtradeSoapHeader();
        header.SYSTEM_CODE = "****";
        header.USERNAME = "******";
        header.PASSWORD = "****";

        RndWebService c = new RndWebService();
        RndWcfWebServiceClient.RndWebServiceClient b = new RndWcfWebServiceClient.RndWebServiceClient();
        ClientSoapHeaderHelper.SetHeader(b.InnerChannel, "SecurityHeader", header);

        
        Response.Write(b.Test());
Jan 27, 2010 at 11:39 AM

Ok, I solved the problem.

I think I forgot to put SoapHeaders attribute to my interface.