none
WCF Message Contracts RRS feed

  • Question

  • 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;

            }

            // TODO: Add your service operations here

        }


    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?

    Friday, March 22, 2013 11:18 AM

All replies

  • What i am trying to achieve is to pass a key to the soapheader like the old web service way.
    Friday, March 22, 2013 11:20 AM
  • 1 observation i made is MessageHeader attribute if i give, the testval is property is not visible in the client end. but if i change it to  "MessageBodyMember" it the same property will becone accesible in client end.

    But why :(

    Friday, March 22, 2013 12:13 PM
  • Still struggling with the same issue. :(

    Saturday, March 23, 2013 8:01 AM