ASP. NET Practice JS Call WebService

Source: Internet
Author: User

[CSharp]View Plaincopyprint?
  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Linq;
  4. Using System.Web;
  5. Using System.Web.Services;
  6. <summary>
  7. Summary description of Jswebservicetest
  8. </summary>
  9. [WebService (Namespace = "http://tempuri.org/")]
  10. [WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
  11. To allow the Web service to be called from the script using ASP. NET AJAX, uncomment the downstream.
  12. [System.Web.Script.Services.ScriptService]
  13. Public class JsWebServiceTest:System.Web.Services.WebService {
  14. Public jswebservicetest () {
  15. //If you are using a design component, uncomment the following line
  16. //initializecomponent ();
  17. }
  18. [WebMethod]
  19. public String HelloWorld () {
  20. return "Hello World";
  21. }
  22. [WebMethod]
  23. public string WelCome (string name)
  24. {
  25. return name+": Welcome";
  26. }
  27. }

Note JS calls the WebService method to uncomment System.web.script.services.scriptservice

[HTML]View Plaincopyprint?
  1. <%@ page language="C #" autoeventwireup="true" codefile="WebServiceForm2.aspx.cs" inherits="Test2_webserviceform2"%>
  2. <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
  3. <HTML xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="Server">
  5. <title></title>
  6. </head>
  7. <body>
  8. <form id="Form1" runat="Server">
  9. <div>
  10. <asp:scriptmanager id="ScriptManager1" runat= "server">
  11. <!--referencing Web services --
  12. <Services>
  13. <asp:servicereference path="~/webservice/jswebservicetest.asmx"/>
  14. </Services>
  15. </asp:scriptmanager>
  16. <input type="button" value= "View" onclick= "jscallweb ();" />
  17. <br />
  18. <input type="button" value="View 2" onclick="jsCallWeb2 ();" />
  19. </div>
  20. </form>
  21. </body>
  22. </html>
  23. <script type="Text/javascript">
  24. Call 1
  25. function Jscallweb () {
  26. Jswebservicetest.helloworld (Outresult);
  27. }
  28. Call 2
  29. function JsCallWeb2 () {
  30. Jswebservicetest.welcome (' Kevin ', Outresult);
  31. }
  32. Output results
  33. function Outresult (Result) {
  34. alert (result);
  35. }
  36. </Script>



ASP. NET Practice JS Call WebService

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.