I have already done it several times, but I have to forget it every time. I have recorded it today.
(1) Add a web service, XXX. asmx.
(2) Add system. web. extensions reference
(3) modify the property of the XXX class to [ScriptService]
(4) Write a method webMethod () at will and change the method attribute to [WebMethod].
(5) Add the test. aspx page and add a webservice reference to form.
: <Asp: ScriptManager ID = "ScriptManager1" runat = "server">
<Services>
<Asp: ServiceReference Path = "XXX. asmx. asmx" InlineScript = "true"/>
</Services>
</Asp: ScriptManager>
(6) write the js method, TestMethod (); which can call our webMethod method. However, when calling the method, use the callback function name of asynchronous call as the parameter.
: Function TestMethod (TestCallBack)
{
XXX. webMethod ();
}
: Fuction TestCallBack (result)
{
// Method
}
(7) Add the following code to the System. Web node in webconfig:
<HttpHandlers>
<Remove verb = "*" path = "*. asmx"/>
<Add verb = "*" path = "*. asmx "validate =" false "type =" System. web. script. services. scriptHandlerFactory, System. web. extensions, Version = 1.0.61025.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "/>
<Add verb = "*" path = "* _ AppService. axd "validate =" false "type =" System. web. script. services. scriptHandlerFactory, System. web. extensions, Version = 1.0.61025.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "/>
<Add verb = "GET, HEAD" path = "ScriptResource. axd "type =" System. web. handlers. scriptResourceHandler, System. web. extensions, Version = 1.0.61025.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "validate =" false "/>
</HttpHandlers>