<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

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

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:44:45
        文檔

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

        Javascript調(diào)用Webservice的多種方法: 代碼如下:using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [webservice(namespace = http://tempuri.org/)] [WebServiceBinding(ConformsT
        推薦度:
        導(dǎo)讀Javascript調(diào)用Webservice的多種方法: 代碼如下:using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [webservice(namespace = http://tempuri.org/)] [WebServiceBinding(ConformsT

        代碼如下:
        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)部分。
        代碼如下:
        <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è)試頁面中找到,自己拼湊加上對(duì)應(yīng)的參數(shù)就可以。
        通過style.behavior來實(shí)現(xiàn)的方法(比較簡(jiǎn)單)
        function getfemale()
        {
        //第一個(gè)參數(shù)是webservice的url,后面是名稱
        female.useService("news.asmx?WSDL","news");
        //設(shè)置一個(gè)回調(diào)函數(shù),service返回結(jié)果的時(shí)候回調(diào);第一個(gè)參數(shù)是回調(diào)函數(shù)的名稱,后面的是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é)果寫如div中
        }
        }
        頁面顯示部分: <div id="female" style="BEHAVIOR:url(WebService.htc)"></div>
        ok,這給我們?cè)陟o態(tài)頁調(diào)用動(dòng)態(tài)的內(nèi)容提供了一種途徑;
        這里如果給getfemale()函數(shù)加上定時(shí)調(diào)用的話,就是一種無刷新更新頁面的機(jī)制了。
        缺點(diǎn)是webservice會(huì)有一定的延遲,即使是本地的webservice也會(huì)比靜態(tài)頁面慢很多,初次打開頁面會(huì)感覺很不協(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ù)客戶機(jī)

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

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

        Javascript調(diào)用Webservice的多種方法: 代碼如下:using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [webservice(namespace = http://tempuri.org/)] [WebServiceBinding(ConformsT
        推薦度:
        標(biāo)簽: 兩個(gè) 方法 多個(gè)
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 久青草视频97国内免费影视| 免费看美女午夜大片| 华人在线精品免费观看| 全亚洲最新黄色特级网站| 亚洲欧美日韩一区二区三区在线| 免费国产人做人视频在线观看| 亚洲精品国产国语| 免费无码又爽又刺激高潮| 亚洲人成未满十八禁网站| 在线观着免费观看国产黄| 综合偷自拍亚洲乱中文字幕| 又黄又大又爽免费视频| jizz日本免费| 亚洲春色在线视频| 2019中文字幕免费电影在线播放 | 无码国产精品一区二区免费式直播| 亚洲精品免费观看| 亚洲大片免费观看| 精品国产成人亚洲午夜福利| 免费特级黄毛片在线成人观看| 亚洲成AV人片高潮喷水| 亚洲国产一成久久精品国产成人综合 | 欧美日韩国产免费一区二区三区| 亚洲人成电影网站色www| 四虎影视永久免费观看地址| 一级毛片a女人刺激视频免费| 国产偷v国产偷v亚洲高清| 69成人免费视频| 视频一区在线免费观看| 亚洲无av在线中文字幕| 97人妻无码一区二区精品免费| 亚洲精品V天堂中文字幕| 久久久久亚洲av成人无码电影| 男人的天堂网免费网站| 亚洲mv国产精品mv日本mv| 免费人成视频在线观看不卡| 日韩免费观看一区| 亚洲aⅴ无码专区在线观看| 亚洲线精品一区二区三区影音先锋 | 毛片免费观看的视频在线| 色多多A级毛片免费看|