Click here to Skip to main content
15,886,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I added a message contract class like below
C#
[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
C#
[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        Hashtable GetHeader();

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

Now in the WCF service i am implementing the property
C#
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.
C#
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?
Posted
Updated 22-Mar-13 1:55am
v3

1 solution

Hi Buddy,
You r using property as operation contract that's why do r not getting values in soap.
Creating property as operation contract is not advicible.
Use property as Datamember as explained in below link
http://stackoverflow.com/questions/556775/wcf-datamember-attribute-on-property-vs-member[^]

Please refer wcf tutorial on below link (Note: Open link in Internet Explorer)
http://wcftutorial.net/Data-Contract.aspx[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900