Programing wcf services 3rd edition


















When you configure the endpoint address, you can add just the relative URI under the base address:. The endpoint address in this case will be the matching base address plus the URI and, again, the host must provide a matching base address. You can use the config file to customize the binding used by the endpoint. To that end, add the bindingConfiguration tag to the endpoint section and name a customized section in the bindings section of the config file. Example demonstrates using this technique to enable transaction propagation.

Chapter 7 explains the function of the transactionFlow tag. As shown in Example , you can reuse the named binding configuration in multiple endpoints simply by referring to it.

WCF allows you to use a default binding that affects all endpoints of all services of the application that uses the config file. A default binding is simply a nameless binding section. For example, in the case of TCP:. The default binding implicitly configures all endpoints that do not explicitly reference a binding configuration. For example, using a default binding, Example is reduced to:.

The problem with the default binding is that when you combine default bindings with named binding configurations, as shown in Figure , the config file may become difficult for humans to parse and understand.

While Figure is a perfectly valid configuration, I recommend against mixing named and default bindings. Either have all your binding configurations named or use only the default configuration.

Another advantage of a named configuration is that it allows you to weave a bit of documentation via the binding configuration name as to what that configuration is trying to achieve. Most if not all of the binding configurations in this book are named for precisely that reason. Programmatic endpoint configuration is equivalent to administrative configuration, but instead of resorting to a config file, you rely on programmatic calls to add endpoints to the ServiceHost instance.

Again, these calls are always outside the scope of the service code. ServiceHost provides overloaded versions of the AddServiceEndpoint method:. You can provide AddServiceEndpoint methods with either relative or absolute addresses, just as with a config file. Example demonstrates programmatic configuration of the same endpoints as in Example When you add an endpoint programmatically, the address is given as a string, the contract as a Type , and the binding as one of the subclasses of the abstract class Binding , as in:.

Throttling therefore makes sense when the area under the spike is relatively small compared with the area under the entire load graph, implying that the probability of the same caller being queued successively is very low.

Every once in a while, in response to a spike, some callers will get buffered, but the system as a whole will still function well. Throttling does not work well when the load increases to a new level and remains constant at that level for a long time as shown in Figure In that case, all it does is defer the problems a bit, eventually causing all callers to time out.

Such a system should be designed from the ground up to handle the higher level of load. Throttling is done per service type; that is, it affects all instances of the service and all its endpoints. This is done by associating the throttle with every channel dispatcher the service uses.

WCF lets you control some or all of the following service consumption parameters:. Indicates the overall number of outstanding clients that can have a transport session with the service.

In plain terms, this represents the maximum overall number of outstanding clients using TCP, IPC, or either of the WS bindings with reliability, security, or both. Because the connectionless nature of a basic HTTP connection implies a very short transport session that exists only for the duration of the call, this number usually has no effect on clients using the basic binding or a WS binding without a transport session; such clients are instead limited by the maximum allowed number of concurrent calls.

The default value is times the processor or cores count. Limits the total number of calls that can currently be in progress across all service instances. This number should usually be kept at 1 to 3 percent of the maximum number of concurrent sessions.

The default value is 16 times the processor or cores count. Controls the total number of concurrently alive contexts. Unless you set this value explicitly, it will implicitly equate to the sum of the maximum concurrent calls and maximum of the concurrent sessions times the processor count. Once set, it will retain its value regardless of the other two properties.

How instances map to contexts is a product of the instance context management mode, as well as context and instance deactivation. NET experts - revised this edition to include the newest productivity-enhancing features of. Juval Lowy is a software architect and the principal of IDesign, specializing in.

NET architecture consulting and advanced training. NET 4. He participates in the Microsoft internal design reviews for future versions of. When the service type is configured for per-call activation , a service instance the CLR object exists only while a client call is in progress.

Every client request that is, a method call on the WCF contract gets a new dedicated service instance. The following list explains how per-call activation works, and the steps are illustrated in Figure :. Dispose on it. WCF then destroys the context. Disposing of the service instance is an interesting point.

As I just mentioned, if the service supports the IDisposable interface, WCF will automatically call the Dispose method, allowing the service to perform any required cleanup. Note that Dispose is called on the same thread that dispatched the original method call, and that Dispose has an operation context presented later. Once Dispose is called, WCF disconnects the instance from the rest of the WCF infrastructure, making it a candidate for garbage collection. Imagine an application that has to serve many clients.

Typically, these clients create the objects they need when the client application starts and dispose of them when the client application shuts down. Those objects may hold expensive or scarce resources, such as database connections, communication ports, or files. A better activation model is to allocate an object for a client only while a call is in progress from the client to the service. That way, you have to create and maintain in memory only as many objects as there are concurrent calls, not as many objects as there are outstanding clients.

My personal experience indicates that in a typical Enterprise system, especially one that involves users, only 1 percent of all clients make concurrent calls in a high-load Enterprise system, that figure rises to 3 percent. Thus, if your system can concurrently sustain expensive service instances, it can still typically serve as many as 10, outstanding clients. This is precisely the benefit the per-call instance activation mode offers.

This means that you can dispose of the expensive resources the service instance occupies long before the client closes the proxy. By that same token, acquiring the resources is postponed until they are actually needed by a client. Keep in mind that creating and destroying a service instance repeatedly on the service side without tearing down the connection to the client with its client-side proxy is a lot cheaper than repeatedly creating an instance and a connection.

The second benefit is that forcing the service instance to reallocate or connect to its resources on every call caters very well to transactional resources and transactional programming discussed in Chapter 7 , because it eases the task of enforcing consistency with the instance state.

The third benefit of per-call services is that they can be used in conjunction with queued disconnected calls described in Chapter 9 , because they allow easy mapping of service instances to discrete queued messages. To configure a service type as a per-call service, you apply the ServiceBehavior attribute with the InstanceContextMode property set to InstanceContextMode.



0コメント

  • 1000 / 1000