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)

FAQs

What is the difference between ASP NET Web service and WCF Web service? ›

In ASP.NET Development services, SOAP messages are exchanged over HTTP, but WCF services can exchange the message using any format over any transport protocol. Though, SOAP is a default format that WCF uses. 10. WCF services have timeouts by default that can be configured.

Is WCF service still used? ›

As of the release of . NET 5, WCF is basically deprecated. While it will still work with . NET Framework for years to come, it won't be supported in .

What replaced WCF? ›

gRPC as a migration path for WCF to .

NET Core and . NET 5 marks a shift in the way that Microsoft delivers remote communication solutions to developers who want to deliver services across a range of platforms. .

Is WCF part of .NET framework? ›

The Windows Communication Foundation (WCF), previously known as Indigo, is a free and open-source runtime and a set of APIs in the . NET Framework for building connected, service-oriented applications.

What are WCF services? ›

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.

Is WCF a REST or SOAP service? ›

WCF is a Microsoft technology for developing web services (mainly using SOAP, but it is sufficiently customizable that it may also be used for REST.

Is WCF end of life? ›

Windows Communication Framework (WCF) may be deprecated in . NET 5/6+, but it doesn't mean your applications are going to be left out in the cold. Just like Web Forms and other . NET Framework technologies, your WCF applications will continue to work for a long time.

Is it right that asp net WEB API has replaced WCF? ›

4. Is it right that ASP.NET Web API has replaced WCF? To suggest that ASP.NET Web API has completely replaced WCF is not entirely accurate. While Web API is the preferred solution for most new HTTP-based applications, WCF is still useful in some situations.

Does WCF exist in .NET Core? ›

CoreWCF is a port of server side of WCF to . NET Core. It is an open source project that is supported by Microsoft.

Can we migrate WCF to asp net Web API? ›

Create a “standard” ASP.NET Core Web API project for the new server, and add a reference to the new class library project. This is necessary to enable the server to use the same replacement classes (previously DataContract) as the client. Now create a controller for each previous WCF ServiceContract in the Web API.

What is the best alternative for WCF? ›

NET 6, I recommend you to use an alternative to WCF: gRPC,CoreWCF,ASP.NET Core MVC. Or use the WCF Web Services Reference Provider Tool, a Visual Studio Connected Services extension that lets you connect . NET 5+, . NET Core, or ASP.NET Core projects to web services.

Is WCF in .NET 6? ›

The WCF client will be updated with the release of CoreWCF to ensure seamless coordination. Starting with the 6.0 release, the WCF client package no longer supports . NET Standard 2.0 and is exclusively for . NET 6.0 and later.

Is .NET a language or framework? ›

. NET (pronounced dot net) is a framework that provides a programming guidelines that can be used to develop a wide range of applications–––from web to mobile to Windows-based applications. The . NET framework can work with several programming languages such as C#, VB.NET, C++ and F#.

What does WCF stand for? ›

The Lions wear the initials WCF on their uniforms in honor of former owner William Clay Ford, the youngest grandson of Ford Motor Company founder Henry Ford, who owned the team from 1963 until his death in 2014. William Clay Ford's daughter, Sheila Ford Hamp, is now the principal owner and chairperson of the franchise.

Are WCF services RESTful? ›

You can use WCF to build RESTful services in . NET. REST (Representational State Transfer) is an architecture paradigm that conforms to the REST architecture principles. The REST architecture is based on the concept of resources: It uses resources to represent the state and functionality of an application.

What are the advantages of ASP.NET Web API over WCF? ›

WEB API is a better choice for simpler, light weight services. WEB API can use any text format including XML and is faster than WCF. WEB API can be used to create full-blown REST Services. WEB API doesn't require any data contracts and doesn't require configurations to the level of WCF.

Is it right that ASP.NET Web API has replaced WCF? ›

4. Is it right that ASP.NET Web API has replaced WCF? To suggest that ASP.NET Web API has completely replaced WCF is not entirely accurate. While Web API is the preferred solution for most new HTTP-based applications, WCF is still useful in some situations.

What is the difference between ASP.NET web App and ASP.NET Web API? ›

We can use MVC to create a Web application that responds as both data and views, while the Web API is used to create HTTP services that only respond as data. The Web API request traces with the actions based on the HTTP services, but the MVC request traces with the action name.

What is the difference between REST API and ASP.NET Web API? ›

Web APIs encompass any API using HTTP or HTTPS. All REST APIs are Web APIs, but not all Web APIs are RESTful. REST APIs are Web APIs that follow specific architectural principles like statelessness and client-server architecture. Technically, they can be stateless or stateful.

References

Top Articles
20 High Protein Casserole Recipes You Can Eat All Week
33+ Vegan Christmas Breakfast Recipes
Pollen Count Centreville Va
Promotional Code For Spades Royale
Shs Games 1V1 Lol
Seething Storm 5E
Marist Dining Hall Menu
30% OFF Jellycat Promo Code - September 2024 (*NEW*)
Riegler &amp; Partner Holding GmbH auf LinkedIn: Wie schätzen Sie die Entwicklung der Wohnraumschaffung und Bauwirtschaft…
Pollen Count Central Islip
What is a basic financial statement?
Cranberry sauce, canned, sweetened, 1 slice (1/2" thick, approx 8 slices per can) - Health Encyclopedia
Knaben Pirate Download
Shariraye Update
Breakroom Bw
Five Day National Weather Forecast
Roster Resource Orioles
Carson Municipal Code
Ruben van Bommel: diepgang en doelgerichtheid als wapens, maar (nog) te weinig rendement
Craigslist Southern Oregon Coast
Aps Day Spa Evesham
Heart and Vascular Clinic in Monticello - North Memorial Health
Self-Service ATMs: Accessibility, Limits, & Features
Food Universe Near Me Circular
Happy Homebodies Breakup
Mumu Player Pokemon Go
Play 1v1 LOL 66 EZ → UNBLOCKED on 66games.io
Culver's Hartland Flavor Of The Day
Hair Love Salon Bradley Beach
Finland’s Satanic Warmaster’s Werwolf Discusses His Projects
The Best Restaurants in Dublin - The MICHELIN Guide
Joey Gentile Lpsg
301 Priest Dr, KILLEEN, TX 76541 - HAR.com
Wait List Texas Roadhouse
Craigslist Com Panama City Fl
Janaki Kalaganaledu Serial Today Episode Written Update
21 Alive Weather Team
R: Getting Help with R
Craigslist Com St Cloud Mn
Citizens Bank Park - Clio
Big Reactors Best Coolant
Greg Steube Height
Random Animal Hybrid Generator Wheel
Dyi Urban Dictionary
Motorcycles for Sale on Craigslist: The Ultimate Guide - First Republic Craigslist
Enter The Gungeon Gunther
The 13 best home gym equipment and machines of 2023
Bradshaw And Range Obituaries
Cvs Minute Clinic Women's Services
Psalm 46 New International Version
Basic requirements | UC Admissions
Southern Blotting: Principle, Steps, Applications | Microbe Online
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 5848

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.