I added a message contract class like below
[MessageContract]
public class Credential
{
private string key = String.Empty;
private string val = String.Empty;
[MessageBodyMember(
Name = "test",
Namespace = "http://www.examples.com"
)]
public string Key
{
get { return key; }
set { this.key = value; }
}
[MessageHeader(
Name = "testval",
Namespace = "http://www.examples.com"
)]
public string Val
{
get { return val; }
set { this.val = value; }
}
}
Added a Service contract like below
[ServiceContract]
public interface IService1
{
[OperationContract]
Hashtable GetHeader();
Credential obj
{
[OperationContract]
get;
[OperationContract]
set;
}
}
Now in the WCF service i am implementing the property
public class Service1 : IService1
{
private Credential _obj;
public Credential obj
{
get { return _obj; }
set { _obj = value; }
}
public Hashtable GetHeader()
{
Hashtable ht = new Hashtable();
foreach (MessageHeaderInfo h in OperationContext.Current.IncomingMessageHeaders)
{
ht.Add(h.Name, h.ToString());
}
return ht;
}
}
Now in the client i am trying to set the message contract object like below.
localhost.Service1 obj = new localhost.Service1();
localhost.Credential objCredential = new localhost.Credential();
objCredential.test = "test";
obj.set_obj(objCredential);
obj.GetHeader();
But the soap header never seems to have the value i assigned to " objCredential.test".Why is it so?