Asp.net script method call webService Method

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.