XmlDictionary and XmlDictionaryString classes to create WCF Message

It is common when you will create Message, you may use below classes

Class Namespace
XmlDictionary System.Xml
XmlDictionaryString System.Xml

Let us investigate purpose of each class one by one.

XmlDictionary class allows us to create a private pair of Key and Value. This key-value pair can be used to represent

  1. Element name
  2. Attribute name
  3. XML namespace declaration.

XmlDictionary class uses XmlDictionaryString class object to create key value pair. If you see below code, we are creating a XmlDictionary object and List of XmlDictionaryString.



dct is object of XmlDictionary and while adding string value in this it returns XmlDictionaryString object.


XmlDictionary dct = new XmlDictionary();
            List<XmlDictionaryString> lstData = new List<XmlDictionaryString>();
            foreach (var r in lstData)
                Console.WriteLine("Key  = {0}  and Value = {1}", r.Key, r.Value);


If you run above code you will get output as below,


We are simply adding returned XmlDictionaryString object to list of XmlDictionaryString.

I hope this post was useful. Thanks for reading Smile


One response to “XmlDictionary and XmlDictionaryString classes to create WCF Message”

  1. […] XmlDictionary and XmlDictionaryString classes to create WCF Message […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com