views:

729

answers:

1

Hi, i am facing a problem here. I am doing a client/server project, which is WCF web service calling to get data.Due to huge data of transfering, i got to change my binding to custom binding programmatically(not by config file.)

I am creating a new user-define binding aka custom binding. example of the class is :

public class MyCustomBinding : CustomBinding

and override a function BindingElementCollection:

public override BindingElementCollection CreateBindingElements()
{
   WSHttpBinding wSHttpBinding = new WSHttpBinding("RMSKeberosBinding"); //this is to load the configuration from app.config. because i want to copy the setting of wsHttpConfig to my custom binding.

   BindingElementCollection wSHttpBindingElementCollection = wSHttpBinding.CreateBindingElements();

   TransactionFlowBindingElement transactionFlowBindingElement = wSHttpBindingElementCollection.Remove<TransactionFlowBindingElement>();
   SymmetricSecurityBindingElement securityElement = wSHttpBindingElementCollection.Remove<SymmetricSecurityBindingElement>();
   MessageEncodingBindingElement textElement = wSHttpBindingElementCollection.Remove<MessageEncodingBindingElement>();
   HttpTransportBindingElement transportElement = wSHttpBindingElementCollection.Remove<HttpTransportBindingElement>();

   GZipMessageEncodingBindingElement gzipElement = new GZipMessageEncodingBindingElement(); // this is from microsoft sample. i want to add gzip as a compress to my message.

   BindingElementCollection newCol = new BindingElementCollection();
   newCol.Add(transactionFlowBindingElement);
   newCol.Add(securityElement);
   newCol.Add(gzipElement);
   newCo .Add(transElement);
   return newCol;
}

what i am trying to do is copy all setting from wshttpbinding, and add on gzip as the message encoder. Compress an encrypted data will lead to a bigger size of the original data size. this is because the SymmetricSecurityBindingElement from WSHttpBinding did the encryption. How to do this in correct way? i want the security setting from wshttpbinding, and also the gzip to work.

thanks.

A: 

You should be able to just use a behavior to apply compression accordingly:

http://weblogs.asp.net/cibrax/archive/2006/03/29/441398.aspx

EDIT: I perhaps should also include the link to the Behavior based compression:

http://weblogs.shockbyte.com.ar/rodolfof/archive/2006/04/06/5632.aspx

MattK
Hi, thanks for the reply. I had viewed the link you gave me previously. Sorry, but i can't see where is the place using the same behavior of WSHttpBinding's security? Does the link u gave, include the encryption?
Geoffrey Wong
From my experience using the code that I linked to, even though the entire encrypted message itself is compressed, it did not lead to a larger message size but instead reduced the message size. The message is at its core is just SOAP (i.e. verbose text), so by utilizing compression you should see gains. Am I misunderstanding what you want to do?
MattK
Hi MattK, thanks for the reply.For my experience in it, whenever i add SymmetricSecurityBindingElement and GZipMessageEncodingBindingElement into the binding element collection(please refer to the code at above),the message is always encrypted at first, then only proceed to compress. I had use Fiddler to check the bandwidth usage. It is so huge after compress an encrypted message. I dunno how to solve this.By the way, the link you had send me, can u show me where is the part that encrypting the message? i can't manage to find the code to encrypt. Thanks MattK.
Geoffrey Wong
My apologies...I had used the behavior based compression so that I could use the standard WSHttpBinding instead of a custom binding. I've edited my initial answer to include the link to that code.
MattK