WCF Custom Behavior

Hi All,

I am looking for some WCF behaviour help. Which will tell me Why we need behavior...wht we can do with it...& how to implement custom behavior. I tried a lot to get this info but didnt impress me much. if anyone have some real good stuff plezzzz share it across.

Thanks a tonzzzzz in advance.



Answer this question

WCF Custom Behavior

  • EWoodruff

    Oops. I meant this:

    EndpointAddress endptadr = new EndpointAddress("urn:ScottsServer");
    WSHttpBinding binding = new WSHttpBinding();
    binding.Security.Mode = SecurityMode.None;

    CFScott = new ChannelFactory<IScott>(binding);
    Uri Via = new Uri("
    http://localhost:16000/Router/");

    proxy = CFScott.CreateChannel(endptadr, Via);


    MessageHeader MessageHeader<string> myHeader = new MessageHeader<string> ( Environment.UserDomainName + "\\" + Environment.UserName,false,"urn:ScottsServer",true);
    MessageHeader MyUntypedHeader = myHeader.GetUntypedHeader("Username", "urn:ScottsReallyCoolApp");

    OperationContextScope scope = new OperationContextScope((IContextChannel)proxy);
    OperationContext.Current.OutgoingMessageHeaders.Add(MyUntypedHeader);

    string ret = proxy.Yo();
    label1.Text = ret;



  • JonasSam

    Just to clarify the scenario that's outlined in the link you brought up:
    As Scott mentioned above, you can easily add headers to an outgoing request manually by using the OperationContext and OperationContextScope objects. I was looking for a way to have this happen automatically without adding code before each call. For this, I added a behavior declaration at the interface level to specify a client-side behavior.

    I don't know if an auto-generated proxy interface will carry this behavior over, and in any case it would mean the class implementing the behavior must be present on the client side. Since this is defined on the interface, it has to be available on the server-side as well.
    If you're accessing a service that you can't modify, maybe you can generate the local copy of the interface using SvcUtil, then modify it to add the behavior attribute.

  • JMarkHowell

    Hi Scott.

    I gone through the Extending WCF documentation. unfortunately it had most of the sections undocumented...basics they have explained but no samples....Anyways i have requirement whch i need to see wthether Behaviour will be helpful to implement it or anyother best option is available in WCF.

    There are certain 3 rd party webservices. which we are using. These services need some Headers so there is a existing Assembly writeen in .net1.0 which takes care of passing those hreader to these services...so client actually interacts with these services through this Assembly which encapsulate this header manipulation logic. we are thinking about replacing this Assembly. We will have WCF Client wich will directly communicate with these Web Services & this WCF client will only pass those Headers that is required by the Web Service. So i am looking out how i can use behaviour to achieve this...since i have gone through the ExtendingWCF i feel i shlud use Proxy behaviour. i would appreciate if u can give some more inputs..or rather provide me some samples help doing this.


  • thenujay

    Hi,

    Check out this post.

    Guy Burstein

    http://blogs.microsoft.co.il/blogs/bursteg



  • James Terwilliger

    Hi Scott

    i need to pass Headers to 3rd Party Web Service Using WCF. I just know tht this Web Service Need some headers thts it. I cant modify Web Service; whatevr i have to do is through WCF cleint. http://weblogs.asp.net/avnerk/archive/2006/04/26/444013.aspx Pending=true this article is very close to my requirements. but am not geeting it how to implement it...cos author has not explained which pice of code shld be placed where i.e Which code shld be part of service & which part shld be aprt of client code...if u have any alternate option available to achieve my requiremnets thn please help me....its urgent..

    Regds

    Vishal.


  • msorrent

    WCF is extremely extensible and behaviors are a way of accessing that. The list of what you can do with custom behaviors is almost endless.... ;>

    It's difficult to answer your questions without knowing exactly what you're trying to accomplish as this is a BIG area. I can point you to some of the SDK samples and some more on www.windowscommunication.net which may give you an idea of what you can do though.

    I would first read through the Extending WCF section in the SDK though to get you started. Once you do that then you can look through some of the Extensibility samples that ships with the SDK.

    Also look at this:

    http://windowscommunication.net/ControlGallery/ControlDetail.aspx Control=2241&tabindex=2

    Which is a pretty simple sample of how I used behaviors to store state at varying levels.

    Hope this helps.

    Thanks!

    Scott



  • woolybutt

    There's actually an easier way to add headers. There's really two easy ways but one involves changing your contract which includes altering your server so that won't do.

    The other way is to just add your headers manually via code on the client:

    EndpointAddress endptadr = new EndpointAddress("urn:ScottsServer");
    WSHttpBinding binding = new WSHttpBinding();
    binding.Security.Mode = SecurityMode.None;

    CFScott = new ChannelFactory<IScott>(binding);
    Uri Via = new Uri("http://localhost:16000/Router/");

    proxy = CFScott.CreateChannel(endptadr, Via);


    MessageHeader MessageHeader<string> myHeader = new MessageHeader<string> ( Environment.UserDomainName + "\\" + Environment.UserName,false,"urn:ScottsServer",true);
    MessageHeader MyUntypedHeader = myHeader.GetUntypedHeader("Username", "urn:ScottsReallyCoolApp");

    OperationContextScope scope = new OperationContextScope((IContextChannel)proxy);
    OperationContext.Current.OutgoingMessageHeaders.Add(msghuntypedFinal);
    OperationContext.Current.OutgoingMessageHeaders.Add(msghuntypedRouter);

    string ret = proxy.Yo();
    label1.Text = ret;

    Let me know if that helps.

    Thanks!

    Scott



  • yonderstar

    Excellent idea, and very easy to implement as well using a clientside message inspector. I've coded one up that does just that. If you want to take a gander send me email at smason@microsoft.com and I'll reply with the sample.

    Thanks!

    Scott



  • WCF Custom Behavior