Internal Classes To Understand WCFMessage: XmlDictionary Class


It is common to use the XmlDictionary class when creating a message.

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

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

The XmlDictionary class uses a XmlDictionaryString class object to create a key value pair. In the following code we are creating an XmlDictionary object and List of XmlDictionaryString.

Untitled-19.gif

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

XmlDictionary dct = newXmlDictionary();
List<XmlDictionaryString> lstData = newList<XmlDictionaryString>();
    lstData.Add(dct.Add("Bat"));
    lstData.Add(dct.Add("Ball"));
    lstData.Add(dct.Add("Wicket"));
    foreach (var r in lstData)
    {
        Console.WriteLine("Key  = {0}  and Value = {1}", r.Key, r.Value);
    }
    Console.ReadKey(true);

If you run the above code you will get output as below:

Untitled-21.gif

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

I hope you now understand the use of the XmlDictionary class. In the next article we will discuss some other important classes required to understand messages in WCF.

Thanks for reading.

Up Next
    Ebook Download
    View all
    Learn
    View all