次の方法で共有


CA2212: Do not mark serviced components with WebMethod

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Item Value
RuleId CA2212
Category Microsoft.Usage
Breaking change Breaking

Cause

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

Rule description

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.

How to fix violations

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

When to suppress warnings

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

See also