I have a .NET 3.5 aspx place with a method marked with the [WebMethod]
attribute. I'm calling this with jQuery, sending JSON in both directions. This all works great. My question is, what does [ScriptMethod]
do when applied to an method? I've tried this and it seems to yield the same result. Are ScriptMethod
and WebMethod
identical and interchangeable, or does one provide functionality and/or overhead that the other doesn't? In general, I find myself confused with all of the options available for implementing web services and I'd like to know what the pros and cons are for each.
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- Using JAX-WS 2.2.5 client with JDK/JRE 1.5
- What is the best way to create a lock from a web a
You use the ScriptMethod attribute in the following 2 scenarios.
If you don't have one of the above requirements; you just need a JSON response using a an ajax request then you can simply use the WebMethod.
There is still one more confusing element here, when do you use the ScriptService attribute? this is used if you are using the Microsoft Ajax Client script framework, this attributes tell the server to generate proxy objects on the client so that you can call functions just like a normal object.
var MyRemoteObject = new RemoteObject();
MyRemoteObject.getMessage(....)
and even when you use the ScriptService attribute you don't need to add the ScriptMethod attribute only in the above scenarios.It was confusing to me at the begining because i thought that the ScriptService and the ScriptMethod attributes works together just like the WebService and WebMethod attributes.
The ScriptMethodAttribute attribute is optional. (However, methods that can be called from client script must have the System.Web.Services..::.WebMethodAttribute attribute applied.). 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.
from - http://msdn.microsoft.com/en-us/library/system.web.script.services.scriptmethodattribute.aspx
EDIT: WebMethod and ScriptMethod are not competing attributes. ScriptMethod could be an additional annotation, as the above para says.