C# Web服务中的Web方法属性是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1243382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:07:54  来源:igfitidea点击:

what is web method attribute in web service?

c#asp.netweb-serviceswebmethod

提问by Tushar Maru

what is web method attribute in web service? fro example

Web服务中的Web方法属性是什么?举个例子

[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public string GetApplicationDomains(string strParameterList)
{

}        

for what purpose this attributes WebMethod and ScriptMethod are used?

使用此属性 WebMethod 和 ScriptMethod 的目的是什么?

回答by rahul

WebMethodattribute identifies this method as a web service method.

WebMethod属性将此方法标识为 Web 服务方法。

The ScriptMethodAttributeattribute is optional.

ScriptMethodAttribute属性是可选的。

If a method is not marked with ScriptMethodAttribute, the method will be called by using the HTTP POST command and the response will be serialized as JSON. You cannot override this setting from script.

如果一个方法没有用ScriptMethodAttribute标记,该方法将使用 HTTP POST 命令调用,响应将被序列化为 JSON。您不能从脚本覆盖此设置。

回答by Dmytrii Nagirniak

WebMethodindicates "the method exposed as part of the XML Web service."
ScriptMethod"Specifies which HTTP verb is used to invoke a method, and the format of the response"

WebMethod表示“作为 XML Web 服务的一部分公开的方法”。
ScriptMethod“指定使用哪个 HTTP 动词来调用方法,以及响应的格式”

回答by Rune Grimstad

The WebMethodattribute enables the method to be called through the web service.

的WebMethod属性能够通过Web服务调用的方法。

The ScriptMethodattribute tells which method should be used to call the method (POST/GET) and with formatting the response should use (JSON or XML)

所述ScriptMethod属性告诉该方法应被用于调用方法(POST / GET)中,用格式化响应应该使用(JSON或XML)