WCF services and ASP.NET - WCF (2024)

  • Article

This topic discusses hosting Windows Communication Foundation (WCF) services side-by-side with ASP.NET and hosting them in ASP.NET compatibility mode.

Hosting WCF side-by-side with ASP.NET

WCF services hosted in Internet Information Services (IIS) can be located with .ASPX pages and ASMX Web services inside of a single, common Application Domain. ASP.NET provides common infrastructure services such as AppDomain management and dynamic compilation for both WCF and the ASP.NET HTTP runtime. The default configuration for WCF is side-by-side with ASP.NET.

WCF services and ASP.NET - WCF (1)

The ASP.NET HTTP runtime handles ASP.NET requests but does not participate in the processing of requests destined for WCF services, even though these services are hosted in the same AppDomain as is the ASP.NET content. Instead, the WCF Service Model intercepts messages addressed to WCF services and routes them through the WCF transport/channel stack.

The results of the side-by-side model are as follows:

  • ASP.NET and WCF services can share AppDomain state. Because the two frameworks can coexist in the same AppDomain, WCF can also share AppDomain state with ASP.NET (including static variables, events, and so on).

  • WCF services behave consistently, independent of hosting environment and transport. The ASP.NET HTTP runtime is intentionally coupled to the IIS/ASP.NET hosting environment and HTTP communication. Conversely, WCF is designed to behave consistently across hosting environments (WCF behaves consistently both inside and outside of IIS) and across transport (a service hosted in IIS 7.0 and later has consistent behavior across all endpoints it exposes, even if some of those endpoints use protocols other than HTTP).

  • Within an AppDomain, features implemented by the HTTP runtime apply to ASP.NET content but not to WCF. Many HTTP-specific features of the ASP.NET application platform do not apply to WCF Services hosted inside of an AppDomain that contains ASP.NET content. Examples of these features include the following:

    • HttpContext: Current is always null when accessed from within a WCF service. Use RequestContext instead.

    • File-based authorization: The WCF security model does not allow for the access control list (ACL) applied to the .svc file of the service when deciding if a service request is authorized.

    • Configuration-based URL Authorization: Similarly, the WCF security model does not adhere to any URL-based authorization rules specified in System.Web’s <authorization> configuration element. These settings are ignored for WCF requests if a service resides in a URL space secured by ASP.NET’s URL authorization rules.

    • HttpModule extensibility: The WCF hosting infrastructure intercepts WCF requests when the PostAuthenticateRequest event is raised and does not return processing to the ASP.NET HTTP pipeline. Modules that are coded to intercept requests at later stages of the pipeline do not intercept WCF requests.

    • ASP.NET impersonation: By default, WCF requests always runs as the IIS process identity, even if ASP.NET is set to enable impersonation using System.Web’s <identity impersonate="true" /> configuration option.

These restrictions apply only to WCF services hosted in IIS application. The behavior of ASP.NET content is not affected by the presence of WCF.

WCF applications that require functionality traditionally provided by the HTTP pipeline should consider using the WCF equivalents, which are host and transport independent:

  • OperationContext instead of HttpContext.

  • ServiceAuthorizationBehavior instead of ASP.NET’s File/URL Authorization.

  • IDispatchMessageInspector or custom layered channels instead of HTTP modules.

  • Impersonation for each operation using WCF instead of System.Web impersonation.

Alternatively, you can consider running your services in WCF’s ASP.NET compatibility mode.

Hosting WCF services in ASP.NET compatibility mode

Although the WCF model is designed to behave consistently across hosting environments and transports, there are often scenarios where an application does not require this degree of flexibility. WCF’s ASP.NET compatibility mode is suitable for scenarios that do not require the ability to host outside of IIS or to communicate over protocols other than HTTP, but that use all of features of the ASP.NET Web application platform.

Unlike the default side-by-side configuration, where the WCF hosting infrastructure intercepts WCF messages and routes them out of the HTTP pipeline, WCF services running in ASP.NET Compatibility Mode participate fully in the ASP.NET HTTP request lifecycle. In compatibility mode, WCF services use the HTTP pipeline through an IHttpHandler implementation, similar to the way requests for ASPX pages and ASMX Web services are handled. As a result, WCF behaves identically to ASMX with respect to the following ASP.NET features:

  • HttpContext: WCF services running in ASP.NET Compatibility Mode can access Current and its associated state.

  • File-based authorization: WCF services running in ASP.NET compatibility mode can be secure by attaching file system access control lists (ACLs) to the service’s .svc file.

  • Configurable URL authorization: ASP.NET’s URL authorization rules are enforced for WCF requests when the WCF service is running in ASP.NET Compatibility Mode.

  • HttpModuleCollection extensibility: Because WCF services running in ASP.NET Compatibility Mode participate fully in the ASP.NET HTTP request lifecycle, any HTTP module configured in the HTTP pipeline is able to operate on WCF requests both before and after service invocation.

  • ASP.NET Impersonation: WCF services run using the current identity of the ASP.NET impersonated thread, which may be different than the IIS process identity if ASP.NET impersonation has been enabled for the application. If ASP.NET impersonation and WCF impersonation are both enabled for a particular service operation, the service implementation ultimately runs using the identity obtained from WCF.

WCF’s ASP.NET compatibility mode is enabled at the application level through the following configuration (located in the application’s Web.config file):

<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /></system.serviceModel>

This value defaults to false if not specified. The value of false indicates that all WCF services running in the application will not run in ASP.NET Compatibility Mode.

Because ASP.NET Compatibility Mode implies request processing semantics that are fundamentally different from the WCF default, individual service implementations have the ability to control whether they run inside of an application for which ASP.NET Compatibility Mode has been enabled. Services can use the AspNetCompatibilityRequirementsAttribute to indicate whether they support ASP.NET Compatibility Mode. The default value for this attribute is Allowed.

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]public class CalculatorService : ICalculatorSession{//Implement calculator service methods.}

The following table illustrates how the application-wide compatibility mode setting interacts with the individual service’s stated level of support:

Application-wide Compatibility Mode setting[AspNetCompatibilityRequirementsMode]

Setting

Observed Result
aspNetCompatibilityEnabled = "true"RequiredService activates successfully.
aspNetCompatibilityEnabled = "true"AllowedService activates successfully.
aspNetCompatibilityEnabled = "true"NotAllowedAn activation error occurs when the service receives a message.
aspNetCompatibilityEnabled = "false"RequiredAn activation error occurs when the service receives a message.
aspNetCompatibilityEnabled = "false"AllowedService activates successfully.
aspNetCompatibilityEnabled = "false"NotAllowedService activates successfully.

Note

IIS 7.0 and WAS allows WCF services to communicate over protocols other than HTTP. However, WCF services running in applications that have enabled ASP.NET compatibility mode are not permitted to expose non-HTTP endpoints. Such a configuration generates an activation exception when the service receives its first message.

For more information about enabling ASP.NET compatibility mode for WCF services, see AspNetCompatibilityRequirementsMode and the ASP.NET Compatibility sample.

See also

  • AspNetCompatibilityRequirementsAttribute
  • Windows Server App Fabric Hosting Features
WCF services and ASP.NET - WCF (2024)

References

Top Articles
What Alcohol Goes in Eggnog? We've Got the Answers
The History of Eggnog (and How to Make It the Old-Fashioned Way)
Benchmark Physical Therapy Jobs
Luxiconic Nails
Fresenius Medical Care to launch 5008 dialysis machine: improved patients` quality of life and efficient use of resources
How to cancel subscriptions on your iPhone through the Settings app
Amazon Ups Drop Off Locations Near Me
Gopher Hockey Forum
Spanish Speaking Daycare Near Me
Carsavers Rental
Jackie Knust Wendel
How To Get Mega Ring In Pokemon Radical Red
Integrations | Information Technology
[PDF] JO S T OR - Free Download PDF
Comparing Each Tacoma Generation, Which is Best?
Fintechzoommortgagecalculator.live Hours
Mobile Maher Terminal
Tinyzonetv.to Unblocked
Craigslist Siloam Springs
Car Complaints Toyota
Binny Arcot
Craigslist Org Hattiesburg Ms
11 Shows Your Mom Loved That You Should Probably Revisit
Juanita Swink Hudson
Kroger Liquor Hours
Araxotok
Norte Asesores Nanda
Zom100 Mangadex
Weather | Livingston Daily Voice
Stellaris Resolutions
Hartford Healthcare Employee Tools
Pokimane Titty Pops Out
Does Dollar General Have Humidifiers
Mtvkay21
Tamara Lapman
Paris 2024: The first Games to achieve full gender parity
Savannah Schultz Leaked
Body made of crushed little stars - Sp1cy_Rice_W1th_J4S - 僕のヒーローアカデミア | Boku no Hero Academia
Chloe Dicarlo
Find your used roadbike, gravel Bike & MTB | buycycle UK
Networks Guided Reading Activity
Nail salons near me in West Hartford. Find a nail shop on Booksy!
M&T Bank Branch Locations
Sxs Korde
Tattoo Shops Buckhannon Wv
Roselli's Pizza Coupons
Sesame Street 4323
Joann Stores Near Me
29+ Des Moines Craigslist Furniture
Sicilys Pizza Promo Code 40 Off
Eugenics Apush
Southwest Airlines Departures Atlanta
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 5957

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.