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

Javascript調用Webservice的多種方法

復制代碼 代碼如下:
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調用webservice+xmlhttp的實現部分。
復制代碼 代碼如下:
<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方法需要發送的那堆東東可以在webservice的測試頁面中找到,自己拼湊加上對應的參數就可以。
通過style.behavior來實現的方法(比較簡單)
function getfemale()
{
//第一個參數是webservice的url,后面是名稱
female.useService("news.asmx?WSDL","news");
//設置一個回調函數,service返回結果的時候回調;第一個參數是回調函數的名稱,后面的是webservice的參數
intCallID=female.news.callService(female_result,"getphoto","female"); //這里有兩個參數.....
}
function female_result(result)//回調函數
{
if(result.error)
{
female.innerHTML=result.errorDetail.string;
}
else
{
female.innerHTML=result.value; //將webservice返回的結果寫如div中
}
}
頁面顯示部分: <div id="female" style="BEHAVIOR:url(WebService.htc)"></div>
ok,這給我們在靜態頁調用動態的內容提供了一種途徑;
這里如果給getfemale()函數加上定時調用的話,就是一種無刷新更新頁面的機制了。
缺點是webservice會有一定的延遲,即使是本地的webservice也會比靜態頁面慢很多,初次打開頁面會感覺很不協調。
第二種方法使用了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).
附注:另一個總結帖子在: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上面有關ajax調用webservice的文章: 
 使用 Ajax 調用 SOAP Web 服務,第 1 部分: 構建 Web 服務客戶機

AspNet技術Javascript調用Webservice的多種方法,轉載需保留來源!

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

主站蜘蛛池模板: 老师洗澡让我吃她胸的视频 | 精选国产AV精选一区二区三区 | 中文有码中文字幕免费视频 | 2022年国产精品久久久久 | 青青草干免费线观看 | 国产在线观看黄 | 嗨嗨快播电影 | 灌饱娇嫩H将军公主最新章节 | 亚洲欧美自拍清纯中文字幕 | 久久久久国产一级毛片高清片 | 寂寞夜晚视频在线观看 | 99久久e免费热视频百度 | 黑人巨茎大战白人女40CMO | 日本一本2017国产 | 牛牛超碰 国产 | 欧美巨大巨粗黑人性AAAAAA | 亚洲一级毛片免费在线观看 | 亚州综合网 | 色噜噜噜亚洲男人的天堂 | 久久婷五月综合色啪首页 | 116美女写真成人午夜视频 | 午夜视频体内射.COM.COM | 热99RE久久精品国产 | 超碰超碰视频在线观看 | 国产欧美一区二区精品久久久 | 精品无人区麻豆乱码1区2 | 久久精品国产亚洲AV影院 | 国产亚洲色婷婷久久精品99 | 久久免费精品视频 | 少妇的肉体AA片免费观看 | 国产精品高清视亚洲一区二区 | 亚洲伊人久久大香线蕉综合图片 | 24小时日本高清免费看 | 又黄又爽又无遮挡在线观看免费 | 在线观看成人3d动漫入口 | 亚洲 制服 欧美 中文字幕 | 一本久道久久综合狠狠躁AV | 亚洲成人日韩 | 2020久久精品永久免费 | 国产成人啪精品视频免费网 | 99久久国产露脸国语对白 |