一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

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

復(fù)制代碼 代碼如下:
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;
}
}

還是俗了點(diǎn)。:)
2. js調(diào)用webservice+xmlhttp的實(shí)現(xiàn)部分。
復(fù)制代碼 代碼如下:
<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>

對(duì)于使用post方法需要發(fā)送的那堆東東可以在webservice的測(cè)試頁(yè)面中找到,自己拼湊加上對(duì)應(yīng)的參數(shù)就可以。
通過(guò)style.behavior來(lái)實(shí)現(xiàn)的方法(比較簡(jiǎn)單)
function getfemale()
{
//第一個(gè)參數(shù)是webservice的url,后面是名稱(chēng)
female.useService("news.asmx?WSDL","news");
//設(shè)置一個(gè)回調(diào)函數(shù),service返回結(jié)果的時(shí)候回調(diào);第一個(gè)參數(shù)是回調(diào)函數(shù)的名稱(chēng),后面的是webservice的參數(shù)
intCallID=female.news.callService(female_result,"getphoto","female"); //這里有兩個(gè)參數(shù).....
}
function female_result(result)//回調(diào)函數(shù)
{
if(result.error)
{
female.innerHTML=result.errorDetail.string;
}
else
{
female.innerHTML=result.value; //將webservice返回的結(jié)果寫(xiě)如div中
}
}
頁(yè)面顯示部分: <div id="female" style="BEHAVIOR:url(WebService.htc)"></div>
ok,這給我們?cè)陟o態(tài)頁(yè)調(diào)用動(dòng)態(tài)的內(nèi)容提供了一種途徑;
這里如果給getfemale()函數(shù)加上定時(shí)調(diào)用的話(huà),就是一種無(wú)刷新更新頁(yè)面的機(jī)制了。
缺點(diǎn)是webservice會(huì)有一定的延遲,即使是本地的webservice也會(huì)比靜態(tài)頁(yè)面慢很多,初次打開(kāi)頁(yè)面會(huì)感覺(jué)很不協(xié)調(diào)。
第二種方法使用了style.代碼就簡(jiǎn)潔多了他使用了css.定義了div的行為.比起第一種方法,就易讀多了:)
style="behavior:url(webservice.htc)"
前提條件是:
if you are using Microsoft IE 5 or later, you can use the behavior/HTML-Component "WebService" to access a Web service. The "WebService" behavior communicates with Web services over HTTP using Simple Object Access Protocol (SOAP).
附注:另一個(gè)總結(jié)帖子在:http://goody9807.cnblogs.com/archive/2005/08/17/216725.html
calling WebServices using Javascript
if you are using Microsoft IE 5 or later, you can use the behavior/HTML-Component "WebService" to access a Web service. The "WebService" behavior communicates with Web services over HTTP using Simple Object Access Protocol (SOAP).
to use the "WebService" behavior, you must attach it to an element using the STYLE attribute, as follows:
style="behavior:url(webservice.htc)">
附上ibm上面有關(guān)ajax調(diào)用webservice的文章: 
 使用 Ajax 調(diào)用 SOAP Web 服務(wù),第 1 部分: 構(gòu)建 Web 服務(wù)客戶(hù)機(jī)

AspNet技術(shù)Javascript調(diào)用Webservice的多種方法,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 99在线免费播放 | 国产精品亚洲自在线播放页码 | 亚洲网站一区 | 国内精品手机在线观看视频 | 国产精品福利一区二区亚瑟 | 日韩精品一区二区三区在线观看 | 欧美成人a| 国产精品免费观看视频 | 亚洲综合激情 | 久久精品国产99久久无毒不卡 | 成年人免费在线视频网站 | 2021久久精品国产99国产精品 | 亚洲第二区 | 六月婷婷综合 | 久久免费区一区二区三波多野 | 黄网站在线观看 | 91久久精品国产免费一区 | 一区二区三区四区五区 | xfplay影音先锋永久资源 | 国产好吊妞视频在线观看 | 亚洲影视久久 | 国产精品久久久久久一区二区 | 国产真实乱在线更新 | 国产91在线免费观看 | 四虎国产永久免费久久 | 97人洗澡从澡人人爽人人模 | 91极品视频在线观看 | 色噜噜狠狠一区二区三区果冻 | 999精品免费视频观看 | 伊人色综合久久成人 | 国产剧情在线视频 | 黄色影片免费观看 | 亚洲精品在线播放视频 | 久久夜色国产精品噜噜 | 亚洲视频网站在线观看 | 在线播放人成午夜免费视频 | 精品国产91乱码一区二区三区 | 91香蕉国产亚洲一二三区 | 欧美激情在线精品三区 | 国产色婷婷精品免费视频 | 国产精品网站在线进入 |