天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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;
}
}

還是俗了點。:)
2. js調(diào)用webservice+xmlhttp的實現(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>

對于使用post方法需要發(fā)送的那堆東東可以在webservice的測試頁面中找到,自己拼湊加上對應(yīng)的參數(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ù)
intCallID=female.news.callService(female_result,"getphoto","female"); //這里有兩個參數(shù).....
}
function female_result(result)//回調(diào)函數(shù)
{
if(result.error)
{
female.innerHTML=result.errorDetail.string;
}
else
{
female.innerHTML=result.value; //將webservice返回的結(jié)果寫如div中
}
}
頁面顯示部分: <div id="female" style="BEHAVIOR:url(WebService.htc)"></div>
ok,這給我們在靜態(tài)頁調(diào)用動態(tài)的內(nèi)容提供了一種途徑;
這里如果給getfemale()函數(shù)加上定時調(diào)用的話,就是一種無刷新更新頁面的機制了。
缺點是webservice會有一定的延遲,即使是本地的webservice也會比靜態(tài)頁面慢很多,初次打開頁面會感覺很不協(xié)調(diào)。
第二種方法使用了style.代碼就簡潔多了他使用了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).
附注:另一個總結(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ù)客戶機

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

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

主站蜘蛛池模板: 欧美狂野乱码一二三四区 | 狠狠色丁香久久婷婷综合_中 | 贵妃高h荡肉呻吟np杨玉环 | 老司机亚洲精品影院 | 再深点灬舒服灬太大了在线视频 | 精品国产一区二区三区久久影院 | 国产视频这里只有精品 | 人妻仑乱少妇88MAV | 国产亚洲精品久久久久久一区二区 | 免费国产综合视频在线看 | 日本强好片久久久久久AAA | 久久国产精品福利影集 | 一二三四电影完整版免费观看 | 国产精品VIDEOS麻豆TUBE | 在线免费观看a视频 | 亚洲欧美日韩在线观看一区二区三区 | 60老妇性xxxxhd | SM脚奴调教丨踩踏贱奴 | 久久视频这里只精品99热在线观看 | 国产精品亚洲AV毛片一区二区三区 | 国内高清在线观看视频 | 找老女人泻火对白自拍 | 久久精品亚洲视频 | 妖精视频在线观看高清 | 姑娘日本大全免费观看版中文翻译 | 综合激情区视频一区视频二区 | 日韩欧美一区二区三区在线视频 | 欧美三级在线完整版免费 | 国产精品无码亚洲区艳妇 | 成人午夜精品无码区久久漫画日本 | 日韩欧无码一区二区三区免费不卡 | 免费欧美大片 | 麻豆国产MV视频 | 最近中文字幕完整版免费 | 涩涩爱涩涩电影网站 | 国产亚洲精品久久久久久白晶晶 | 黄网13区| 日本精油按摩 | 一本之道加勒比在线观看 | 中文字幕一区中文亚洲 | 亚洲综合色婷婷在线影院 |