Welcome to Windows Communication Foundation (WCF)
Top Tasks :

WCF Team Bloggers

Browse by Tags

All Tags » Answers » Indigo » Behaviors   (RSS)

  • Setting the Configuration Name

    What's the difference between the Name and ConfigurationName on service contracts and behaviors? The Name property sets the name of the service in metadata while the ConfigurationName property sets the name of the service in configuration. Metadata is the part of the service description that is transmitted to others when they interrogate your service. Configuration is the purely local settings for controlling the service. Since Name is more commonly used, I'll just run through a quick example focusing on setting ConfigurationName instead. Here I've got a service contract and implementation setting both the Name and ConfigurationName properties. [ServiceContract(Name= "NotIService" , ConfigurationName= "IService" )] public interface IMyService { [OperationContract] void DoNothing(); } [ServiceBehavior(Name = "NotService" , ConfigurationName = "Service" )] public class MyService : IMyService { public void DoNothing() { } } In my app.config file, the way I'd refer to that service and service endpoint is by the ConfigurationName. < service name ="Service" > < endpoint address ="http://localhost:8000/" binding ="basicHttpBinding" bindingConfiguration ="myBindingConfiguration" contract ="IService" /> </ service > On the other hand, everywhere in the metadata, generated proxy, and even the generated proxy configuration file the service will appear as NotIService and NotService. Next time: Disabling the Visual Studio Service Host Read More...
  • Using Call Context Initializers for Cleanup

    I'm using framework features that have thread-local settings. These settings then get leaked to other client calls. How can I stop this from happening? The problem here is that WCF doesn't know about these thread-local setting changes that you've made and so doesn't know that they need to be cleaned up. WCF by default is more frugal than other stacks, such as ASP.NET, when it comes to protecting state. Saving and restoring lots of thread-local settings takes time regardless of whether you actually did something with those settings or not. WCF tries not to do as much on your behalf so that you don't have to pay for cleanup unless you're using those features. It does however give you the hooks necessary to arrange for this cleanup to take place at the appropriate time. The ICallContextInitializer interface lets you hook the beginning and end of operation calls. Hooking the end of the call allows you to cleanup these setting changes. It's easiest to insert an ICallContextInitializer by applying an endpoint behavior to your application endpoints. class MyInitializer : ICallContextInitializer { public void AfterInvoke( object correlationState) { // Clean up thread-local settings here } public object BeforeInvoke(InstanceContext instanceContext, IClientChannel channel, Message message) { return null ; } } class MyInitializerBehavior : IEndpointBehavior { public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { // Add instances of your call context initializer to the CallContextInitializers collection // of the appropriate operations located at endpointDispatcher.DispatchRuntime.Operations. } public void Validate(ServiceEndpoint endpoint) { } } Next time we'll look at a more complete example of using ICallContextInitializer to solve a problem with setting up thread-local settings as well. Next time: Using Call Context Initializers for Culture Read More...
  • Channel Factory Behaviors

    How do I attach a custom behavior to a dynamically generated proxy object? This one should be easy if you've read the past two articles about modifying a ChannelFactory after creation. Although behaviors can't be specified while creating the ChannelFactory, the ChannelFactory has a local endpoint object that can have behaviors attached. Changing the endpoint for behaviors works exactly the same as changing the endpoint for contracts. As with all modifications to endpoints though, you need to make all changes prior to calling Open (or the first call with proxies) or you'll find that the endpoint has become immutable. Next time: Reader Quotas with Untyped Messages Read More...

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us