Jakka .NET

I am Suresh Jakka, software architect at GeoCue Corp, Madison, Alabama. I have been reading serveral tech blogs and learning a lot. It is about time for me to start a blog on .NET in general so that others can learn from my experiences. Here I will be blogging about obstacles that I encounter in my day-to-day programming world and about the solutions I found.

Monday, March 22, 2010

Changing message sizes in ClearUserNameBinding

If you want to send the Username credentials in WCF, you have to establish some kind of secure communication, like SSL. This is overkill for many of the intranet applications where we do not require that much security. Yaron Naveh wrote an excellent custom binding to be able to send the username credentials in clear text. Thank you Yaron Naveh for an oustanding custom binding. This binding uses default settings of basicHttpBinding for most of the properties like message buffer size. Here I am trying to show you how to change these values in this custom binding.

I am here setting all the values to maxium.

Step1:

In AutoSecuredHttpTransportElement() constructor, initialize the values to maximum possible

public AutoSecuredHttpTransportElement()

{
          MaxReceivedMessageSize = int.MaxValue;
         MaxBufferSize = int.MaxValue;
         MaxBufferPoolSize = long.MaxValue;
}

Step 2:

 In CreateBindingElements() method create XMLDictionaryReaderQutotas object and set the same on TextMessageEncodingBindingElement. Here is the modified version of this method.

public override BindingElementCollection CreateBindingElements()

{
         XmlDictionaryReaderQuotas rqMax = XmlDictionaryReaderQuotas.Max;
        TextMessageEncodingBindingElement textBE = new TextMessageEncodingBindingElement();
        textBE.MessageVersion = this.messageVersion;
       
       rqMax.CopyTo(textBE.ReaderQuotas);
       var res = new BindingElementCollection();
       res.Add(textBE);

       res.Add(SecurityBindingElement.CreateUserNameOverTransportBindingElement());
      res.Add(new AutoSecuredHttpTransportElement());

      return res;
}

Note: Make sure that you have "System.Runtime.Serialization" version 3.0.0.0 and above in your references. Becuase if you have version 2.0.0.0, you will get compile error as this version does not allow setting properties on ReaderQuotas.

That's it. Now your binding can receive lot more data than default one...

In my next blog, I will show you how to use this binding in Silverlight.

Have fun and happy coding...see you later...

0 Comments:

Post a Comment

<< Home