WCF message contracts

Mar 22, 2013 at 11:45 AM
I added a message contract cliass like below

[MessageContract]
public class HelloResponseMessage
{
private string localResponse = String.Empty;
private string extra = String.Empty;

[MessageBodyMember(
Name = "testbody",
Namespace = "test")]
public string Response
{
get { return localResponse; }
set { localResponse = value; }
}

[MessageHeader(
Name = "test",
Namespace = "test",
MustUnderstand = true
)]
public string ExtraValues
{
get { return extra; }
set { this.extra = value; }
}
}

Added a Service contract like below

[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

HelloResponseMessage obj
{
[OperationContract]
get;
[OperationContract]
set;
}
// TODO: Add your service operations here
}

Now in the WCF service i am implementing the property

public class Service1 : IService1
{
private HelloResponseMessage _obj;
public HelloResponseMessage obj
{
get { return _obj; }
set { _obj = value; }
}
public string GetData(int value)
{
string str = obj.Response;
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)
{
Hashtable ht = new Hashtable();
foreach (MessageHeaderInfo h in OperationContext.Current.IncomingMessageHeaders)
{
ht.Add(h.Name, h.ToString());
}
// string str = obj.Response;
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}

Now in the client i am trying to set the message contract object like below.

localhost.Service1 obj = new localhost.Service1();
localhost.HelloResponseMessage objr = new localhost.HelloResponseMessage();
localhost.CompositeType objc=new localhost.CompositeType();


objc.BoolValue=true;
objc.StringValue="test";
objr.ResponseToGreeting = "Hi";

obj.set_obj(objr);
obj.GetDataUsingDataContract(objc);

But the soap header never seems to have the value i assigned to "HelloResponseMessage".Why is it so?