[csharp] view plaincopyprint?
class="dp-c" start="1">
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
-
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.Web.Script.Services.ScriptService]
- public class JsWebServiceTest : System.Web.Services.WebService {
-
- public JsWebServiceTest () {
-
-
-
- }
-
- [WebMethod]
- public string HelloWorld() {
- return "Hello World";
- }
-
- [WebMethod]
- public string WelCome(string name)
- {
- return name+":欢迎光临";
- }
-
- }
注意事项 js调用webservice 方法 要取消注释 system.web.script.services.scriptservice
[html] view plaincopyprint?
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebServiceForm2.aspx.cs" Inherits="test2_WebServiceForm2" %>
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:ScriptManager ID="ScriptManager1" runat="server">
-
- <Services>
- <asp:ServiceReference Path="~/WebService/JsWebServiceTest.asmx"/>
- </Services>
- </asp:ScriptManager>
- <input type="button" value="查看" onclick="jsCallWeb();" />
- <br />
- <input type="button" value="查看2" onclick="jsCallWeb2();" />
- </div>
- </form>
- </body>
- </html>
- <script type="text/javascript">
- //调用1
- function jsCallWeb() {
- JsWebServiceTest.HelloWorld(outResult);
- }
- //调用2
- function jsCallWeb2() {
- JsWebServiceTest.WelCome('kevin', outResult);
- }
- //输出结果
- function outResult(result) {
- alert(result);
- }
-
- </script>