Configuring TCP Connections
Unlike HTTP connections, WCF does not leverage classes in the .NET Framework to manage TCP connection lifetime. Instead, WCF uses a connection pool to cache connections. The connection pool can be managed using the ConnectionPoolSettings property of the TcpTransportBindingElement binding element. The ConnectionPoolSettings property returns an instance of the TcpConnectionPoolSettings class. This class has three properties that help manage connections in the connection pool: IdleTimeout, LeaseTimeout, and MaxOutboundConnectionsPerEndpoint.
Recycling Idle Connections
The IdleTimeout property specifies how low a connection can remain idle in the connection pool before it is closed and removed from the connection pool. The default value is set to two minutes. Setting this value lower can be useful in load-balancing scenarios by increasing the likelihood that idle connections will be recycled.
Adjusting Connection Lifetime
The LeaseTimeout property specifies how long a connection can be active before it is eligible for recycling. After the lifetime is elapsed, idle connections can be closed and removed from the connection pool. The default value is set to five minutes. Setting this value lower can be useful in load balancing scenarios by decreasing the time before connections can be rebalanced across a server farm.
Increasing Number of Connections
The MaxOutboundConnectionsPerEndpoint property specifies the maximum number of connections that can be cached in the connection pool. By default the value is set to 10 connections. Increasing this value may improve performance and scalability in server-to-server or multithreaded client communication scenarios.
Using LINQ with WCF
Language Integrated Query (LINQ) is one of the new technologies available in .NET Framework 3.5 that allows for data to be queried using C# or Visual Basic .NET. Traditionally, data is queried by an application using a string expression, such as SQL or XPath query expressions, without the benefits of compile time checking or IntelliSense support. LINQ enables these capabilities by making a query a first-class language construct. LINQ supports several data sources including SQL Server databases, XML documents, ADO.NET DataSets, and .NET objects. LINQ provides a single mechanism for querying data across these different data sources. Using LINQ can help bridge the world of data and the world of objects.
Exposing LINQ-to-SQL Entities
LINQ-to-SQL refers to the features in LINQ that expose relational data stored in SQL Server as objects. This is great for mapping entities stored within tables in the database to objects within an application. This is often referred to as object-relational mapping (ORM). To help facilitate the mapping process, Visual Studio 2008 provides the Object Relational Designer. This provides a visual designer for creating LINQ-to-SQL entities. Figure A.3 shows the Object Relational Designer for LINQ-SQL entities.
- Figure A.3 LINQ-to-SQL Object Relational Designer
One thing to know is that the designer does not expose LINQ-to-SQL entities using the DataContractSerializer by default. This means that LINQ-to-SQL entities cannot be exposed over WCF services. The capability to expose entities stored in a database using a service is important to developers building service-oriented applications. Fortunately, Microsoft provided a property called Serialization Mode, which is available on the LINQ-to-SQL design surface. Setting this property to UniDirectional allows LINQ-to-SQL entities to be attributed with the [DataContract] and [DataMember] attributes. This exposes LINQ-to-SQL entities as a data contract that can be serialized by WCF. This setting is also available using the SqlMetal.exe command-line utility. This utility can be used to generate code for LINQ-to-SQL entities from a SQL Server database. Passing the /serialization:Unidirectional parameter on the command line instructs SqlMetal.exe to generate types that can be serialized using WCF.
This page intentionally left blank
Index
Post a comment