Friday, May 4, 2012

WCF 4.5 and the ASP.NET Web API got some cool changes.


WCF Simplification Features:

Simplified Generated Configuration Files
When you add a service reference in Visual Studio or use the SvcUtil.exe tool, a client configuration file is generated. In previous versions of WCF these configuration files contained the value of every binding property even if its value is the default value. In WCF 4.5 the generated configuration files contain only those binding properties that are set to a non-default value.

Contract-First Development
WCF now has support for contract-first development. The svcutl.exe has a /serviceContract switch which allows you to generate service and data contracts from a WSDL document.

Add Service Reference from a Portable Subset Project
Portable subset projects enable .NET assembly programmers to maintain a single source tree and build system while still supporting multiple .NET platforms (desktop, Silverlight, Windows Phone, and XBOX). Portable subset projects only reference .NET portable libraries which are a .NET framework assembly that can be used on any core .NET platform. The developer experience is the same as adding a service reference within any other WCF client application. For more information, see Add Service Reference in a Portable Subset Project.

ASP.NET Compatibility Mode Default Changed
WCF provides ASP.NET compatibility mode to grant developers full access to the features in the ASP.NET HTTP pipeline when writing WCF services. To use this mode, you must set the aspNetCompatibilityEnabled attribute to true in the <serviceHostingEnvironment> section of web.config. Additionally, any service in this appDomain needs to have the RequirementsMode property on its AspNetCompatibilityRequirementsAttribute set to Allowed or Required. By default AspNetCompatibilityRequirementsAttributeis now set to Allowed. For more information, see What's New in Windows Communication Foundation 4.5 and WCF Services and ASP.NET.

XmlDictionaryReaderQuotas
XmlDictionaryReaderQuotas contains configurable quota values for XML dictionary readers which limit the amount of memory utilized by an encoder while creating a message. While these quotas are configurable, the default values have changed to lessen the possibility that a developer will have to set them explicitly.

WCF Configuration Validation
As part of the build process within Visual Studio, WCF configuration files are now validated for attributes defined within the project. A list of validation errors or warnings is displayed in Visual Studio if the validation fails.


XML Editor Tooltips
In order to help new and existing WCF service developers to configure their services, the Visual Studio XML editor now provides tooltips for every configuration element and its properties that is part of the service configuration file.

Streaming Improvements
Added support for true asynchronous streaming where the send side now does not block threads if the receive side is not reading or slow in reading thereby increasing scalability. Removed the limitation of message buffering when a client sends a streamed message to an IIS hosted WCF service.

Simplifying Exposing an Endpoint Over HTTPS with IIS
An HTTPS protocol mapping has been added to simplify exposing an endpoint over HTTPS. To enable an HTTPS endpoint, ensure your website has an HTTPS binding and SSL certificate configured, and then simply enable HTTPS for the virtual directory that hosts the service.


Generating a Single WSDL Document
Some third-party WSDL processing stacks are not able to process WSDL documents that have dependencies on other documents through a xsd:import. WCF now allows you to specify that all WSDL information be returned in a single document. To request a single WSDL document append “?singleWSDL” to the URI when requesting metadata from the service.

WebSocket Support
WebSockets is a technology that provides true bidirectional communication over ports 80 and 443 with performance characteristics similar to TCP. Two new bindings have been added to support communication over a WebSocket transport. NetHttpBinding and NetHttpsBinding. For more information see: System-Provided Bindings.

XML Editor Tooltips
In order to help new and existing WCF service developers to configure their services, the Visual Studio XML editor now provides tooltips for every configuration element and its properties that is part of the service configuration file.

Configuring WCF Services in Code
Windows Communication Foundation (WCF) allows developers to configure services using configuration files or code. Configuration files are useful when a service needs to be configured after being deployed. When using configuration files, an IT professional only needs to update the configuration file, no recompilation is required. Configuration files, however, can be complex and difficult to maintain. There is no support for debugging configuration files and configuration elements are referenced by names which makes authoring configuration files error-prone and difficult. WCF also allows you to configure services in code. In earlier versions of WCF (4.0 and earlier) configuring services in code was easy in self-hosted scenarios, the ServiceHost class allowed you to configure endpoints and behaviors prior to calling ServiceHost.Open. In web hosted scenarios, however, you don’t have access to the ServiceHost class. To configure a web hosted service you were required to create a ServiceHostFactory that created the ServiceHost and performed any needed configuration. Starting with .NET 4.5, WCF provides an easier way to configure both self-hosted and web hosted services in code. For more information, see Configuring WCF Services in Code.

ChannelFactory Caching
WCF client applications use the ChannelFactory class to create a communication channel with a WCF service. Creating ChannelFactory instances incurs some overhead because it involves the following operations:

1. Constructing the ContractDescription tree

2. Reflecting all of the required CLR types

3. Constructing the channel stack

4. Disposing of resources

Compression and the Binary Encoder
Beginning with WCF 4.5 the WCF binary encoder adds support for compression. The type of compression is configured with the CompressionFormat property. Both the client and the service must configure the CompressionFormat property. Compression will work for HTTP, HTTPS, and TCP protocols. If a client specifies to use compression but the service does not support it a protocol exception is thrown indicating a protocol mismatch. For more information, see Choosing a Message Encoder

UDP
Support has been added for a UDP transport which allows developers to write services that use “fire and forget” messaging. A client sends a message to a service and expects no response from the service.

Multiple Authentication Support
Support has been added to support multiple authentication modes, as supported by IIS, on a single WCF endpoint when using the HTTP transport and transport security. IIS allows you to enable multiple authentication modes on a virtual directory, this feature allows a single WCF endpoint to support the multiple authentication modes enabled for the virtual directory where the WCF service is hosted.

IDN Support
Support has been added to allow for WCF services with Internationalized Domain Names. For more information see WCF and Internationalized Domain Names.

HttpClient
A new class called HttpClient has been added to make working with HTTP requests much easier. For more info, see Making apps social and connected with HTTP services and HttpClient Upload Sample.

Configuration Intellisense
Attribute values in configuration files for custom attributes defined in the project now support intellisense to facilitate working with configurations quickly and accurately.

Configuration tooltips
WCF elements and attributes now have tooltips in the XML editor, to more easily and accurately identify the purpose of the element or attribute.

Paste Data as Classes
In a WCF project, data types defined in XML (such as are exposed in a service) can be pasted directly into a code page. The XML type will be pasted as a CLR type. See Using Paste XML as Classes for more details.

No comments: