We recommend using Visual Studio 2017

CA2212: Do not mark serviced components with WebMethod


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CA2212: Do not mark serviced components with WebMethod.

|Breaking Change|Breaking|

A method in a type that inherits from System.EnterpriseServices.ServicedComponent is marked with System.Web.Services.WebMethodAttribute.

WebMethodAttribute applies to methods within an XML Web service that were created by using ASP.NET; it makes the method callable from remote Web clients. The method and class must be public and executing in an ASP.NET Web application. ServicedComponent types are hosted by COM+ applications and can use COM+ services. WebMethodAttribute is not applied to ServicedComponent types because they are not intended for the same scenarios. Specifically, adding the attribute to the ServicedComponent method does not make the method callable from remote Web clients. Because WebMethodAttribute and a ServicedComponent method have conflicting behaviors and requirements for context and transaction flow, the behavior of the method will be incorrect in some scenarios.

To fix a violation of this rule, remove the attribute from the ServicedComponent method.

Do not suppress a warning from this rule. There are no scenarios where combining these elements is correct.