国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > JS > 正文

Javascript調(diào)用Webservice的多種方法

2024-09-06 12:41:22
字體:
供稿:網(wǎng)友
代碼如下:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[webservice(namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service ()
{
//uncomment the following line if using designed components
//InitializeComponent();
}
[webmethod]
public string SayHelloTo(string Name)
{
return "Hello "+Name;
}
}

還是俗了點。:)
2. js調(diào)用webservice+xmlhttp的實現(xiàn)部分。
代碼如下:
<html>
<title>Call webservice with javascript and xmlhttp.</title>
<body>
<script language="javascript"><!--


//test function with get method.
function RequestByGet(data){
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//Webservice location.
var URL="http://localhost:1323/WebSite6/Service.asmx/SayHelloTo?Name=Zach";
xmlhttp.Open("GET",URL, false);
xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");
xmlhttp.SetRequestHeader ("SOAPAction","http://tempuri.org/SayHelloTo");
xmlhttp.Send(data);
var result = xmlhttp.status;
//OK
if(result==200) {
document.write(xmlhttp.responseText);
}
xmlhttp = null;
}

//test function with post method
function RequestByPost(value)
{
var data;
data = '<?xml version="1.0" encoding="utf-8"?>';
datadata = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
datadata = data + '<soap:Body>';
datadata = data + '<SayHelloTo xmlns="http://tempuri.org/">';
datadata = data + '<Name>'+value+'</Name>';
datadata = data + '</SayHelloTo>';
datadata = data + '</soap:Body>';
datadata = data + '</soap:Envelope>';

var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var URL="http://localhost:1323/WebSite6/Service.asmx";
xmlhttp.Open("POST",URL, false);
xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=gb2312");
xmlhttp.SetRequestHeader ("SOAPAction","http://tempuri.org/SayHelloTo");
xmlhttp.Send(data);
document.write( xmlhttp.responseText);
}


// --></script>

<input type="button" value="CallWebserviceByGet" onClick="RequestByGet(null)">
<input type="button" value="CallWebserviceByPost" onClick="RequestByPost('Zach')">
</body>
</html>

對于使用post方法需要發(fā)送的那堆東東可以在webservice的測試頁面中找到,自己拼湊加上對應的參數(shù)就可以。
通過style.behavior來實現(xiàn)的方法(比較簡單)
function getfemale()
{
//第一個參數(shù)是webservice的url,后面是名稱
female.useService("news.asmx?WSDL","news");
//設(shè)置一個回調(diào)函數(shù),service返回結(jié)果的時候回調(diào);第一個參數(shù)是回調(diào)函數(shù)的名稱,后面的是webservice的參數(shù)
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 观塘区| 横峰县| 麦盖提县| 历史| 长武县| 巨鹿县| 平南县| 宽甸| 东城区| 宝应县| 临沭县| 云梦县| 海南省| 利川市| 会宁县| 绥芬河市| 万年县| 南京市| 德令哈市| 武冈市| 武汉市| 澜沧| 内黄县| 顺平县| 沂南县| 城市| 丰原市| 蚌埠市| 南川市| 康乐县| 阿勒泰市| 张北县| 林周县| 松溪县| 革吉县| 张家界市| 当雄县| 会理县| 宕昌县| 陵水| 西宁市|