none
ApplyClientBehavior not called (sometimes) in IOperationBehavior

    Question

  • I noticed this today and wanted to know if anyone could pinpoint the reason it is happening:

     

    Background:

     

    I implemented an OperationBehavior in the form of an attribute as follows:

     

    public class ExtensionAttribute: Attribute, IOperationBehavior

    { ...

     

     

    I decorate a service method with the attribute and run the service and a client that calls the service.

     

    I found that the ApplyDispatchBehavior method on the OperationBehavior class gets invoked but the ApplyClientBehavior doesn't when the client code doesn't explicitly create the channel using the ChannelFactory's CreateChannel method. 

     

    If you simply add a service reference and new up the proxy directly relying on the information in your config file and the proxy to do all the setup work for you, and the call a method on the proxy (which is probably what most client side developers will do) the ApplyClientBehavior never gets called.

     

    Can anyone offer some insight as to why this is true?

     

    Thursday, June 28, 2007 7:27 PM

Answers

  • It is actually happening here because the client used does not have the operationBehavior. When you use client generated with add service reference, the behaviors are not added. Client is generated from the service wsdl. Behaviors are not exported to wsdl. These would not be in wsdl as these are just runtime entities. You could add this behaviorattribute explicitly in generated code.

    Thursday, June 28, 2007 10:18 PM
    Moderator

All replies

  • It is actually happening here because the client used does not have the operationBehavior. When you use client generated with add service reference, the behaviors are not added. Client is generated from the service wsdl. Behaviors are not exported to wsdl. These would not be in wsdl as these are just runtime entities. You could add this behaviorattribute explicitly in generated code.

    Thursday, June 28, 2007 10:18 PM
    Moderator
  • Do you have an example of how to apply this attribute on the client side? What I am trying to do is override the XmlObjectSerializer to preserve object references (i.e. New DataContractSerializer(type, name, ns, knownTypes, &H7FFF, False, True, Nothing).  Any help would be appreciated.
    Tuesday, January 06, 2009 5:34 PM