首先,一个属性用于用元数据“装饰”一个项目(这可能会改变项目的行为)。在这种情况下,WebMethod
只有服务器通知 ASP.Net 它正在装饰的方法将被称为 Web 服务方法(例如 MyWebService.asmx/EnrichmentXml)。类的构造函数的Description
命名参数对应于类的一个属性。由于没有在您的方法中实际实例化,因此您无法访问 decorating 的任何成员。WebMethodAttribute
Description
WebMethodAttribute
WebMethodAttribute
WebMethodAttribute
我建议如下:
namespace MyNamespace {
public class MyWebServiceClass {
private const string DESCRIPTION = "Locate Enrichment XML Doc";
[WebMethod(MessageName = "EnrichmentXml", Description = DESCRIPTION)]
public XmlDocument EnrichmentXml(string xmlRequest)
{
SaveLog(DESCRIPTION + " method was called.");
}
}
}