<%@ WebService Language=”C#” Class=”QuotationService” %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;
[WebService(Namespace = “http://tempuri.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class QuotationService : System.Web.Services.WebService
{
[WebMethod]
public string GetQuote()
{
List<string> quotes = new List<string>();
quotes.Add(“The fool who is silent passes for wise.”);
quotes.Add(“The early bird catches the worm.”);
quotes.Add(“If wishes were true, shepherds would be kings.”);
Random rnd = new Random();
return quotes[rnd.Next(quotes.Count)];
}
}
ptg
Calling Web Services from the Client 1779
40
})
});
});
</script>
</head>
<body>
<form id=”form1” runat=”server”>
<div>
<input id=”btnGet” type=”button” value=https://bbs.csdn.net/topics/”Get Quote” />
<br /><br />
<span id=”spanQuote”></span>
</div>
</form>
</body>
</html>
uj5u.com熱心網友回復:
<%@ Page Language=”C#” %><!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 id=”Head1” runat=”server”>
<title>Show Web Service Method</title>
<script type=”text/javascript” src=https://bbs.csdn.net/topics/”./Scripts/jquery-1.4.1.js”></script>
<script type=”text/javascript”>
$(document).ready(function () {
$(“#btnGet”).click(function () {
$.ajax({
type: “POST”,
dataType: “json”,
contentType: “application/json”,
url: “QuotationService.asmx/GetQuote”,
success: function (data) {
$(“#spanQuote”).html(data.d);
},
error: function () {
alert(“The call to the web service failed.”);
}
CHAPTER 40 Client-Side AJAX with jQuery
From the Library of Wow! eBook
uj5u.com熱心網友回復:
沒有Restful能訪問嗎?我覺得不能直接通過ajax呼叫web services。
uj5u.com熱心網友回復:
可以訪問的。不過只是不推薦這么用而已。
https://blog.csdn.net/lovecruel/article/details/6697764
uj5u.com熱心網友回復:
默認webservice只支持SOAP如果要支持GET/POST
https://blog.csdn.net/weixin_34143774/article/details/89750606
uj5u.com熱心網友回復:
無需webservice只需要在aspx.cs 頁面內使用
[WebMethod] 給一個靜態公開方法標記一下即可
https://www.cnblogs.com/sxhlf/p/6709264.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/146988.html
標籤:ASP.NET
上一篇:<新手>下面的24個不會,求解
