webservice 如何允许远程访问?如果使用javascript 调用 webservice

1、 在<system.web></system.web>之间加下面一段

<webServices>

                <protocols>

                     <add name="HttpSoap"/>

                     <add name="HttpPost"/>

                     <add name="HttpGet"/>

                     <add name="Documentation"/>

                </protocols>

           </webServices>

因为我的webservice是使用javascript 在页面调用,而且采用post方式通过httprequest调用webservice,所以

其实只需要<add name="HttpPost"/> 这个配置

2、

      使用javascript 调用 webservice

   var PNRList=new Array(<%=PNRArray %>);---c#代码中定义的string数组
   var currentIndex=-1;
   function StartCheckPNRStatus() --
   {
        if(PNRList.length!=0)
        {
           setTimeout(checkStatus,2000);--页面加载完毕后,2秒调用方法

      //setInterval(checkStatus,2000);使用定时器
        }
   }

 

 function checkStatus()
    {
        currentIndex++;
        if(currentIndex==PNRList.length)
        {
            //clearInterval(timerHandle) 定时器,在前面定义个timerhandle

        }
        else
        {
            var httpRequest;
            if(window.XMLHttpRequest)
            {
                httpRequest=new window.XMLHttpRequest();
            }
            else
            {
                httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
            }
            httpRequest.onreadystatechange=function ()
            { 

                if( httpRequest.readyState==4 )
                {
                    if( httpRequest.status==200)
                    {
                        var xmlDom=httpRequest.responseXML.documentElement;
                        var PNRStatus=xmlDom.childNodes(0).text;--由于我返回的是字符串,所以可以这样取值
                        //alert(PNRStatus)
                        spanPNRStatus.innerText=PNRStatus;
                        if(PNRStatus!="RR")
                        {
                           /* spanLogBtn.style.display="";
                            spanCheckBtn.style.display="";
                            noRRCount++;
                            var spanNumOfTicket=document.getElementById("spanNumOfTicket"+PNRList[currentIndex]);//失败订单票数
                            var spanPriceDue=document.getElementById("spanPriceDue"+PNRList[currentIndex]);//失败订单金额
                            totalTicketNum+=parseInt(spanNumOfTicket.innerText);
                            totalPriceDue+=Number(spanPriceDue.innerText);
                            //给数据统计头赋值
                            var spanTotalOrderCount=document.getElementById("spanTotalOrderCount");
                            var spanRRCount=document.getElementById("spanRRCount");
                            var spanNoRRCount=document.getElementById("spanNoRRCount");
                            var spanTotalTicketNum=document.getElementById("spanTotalTicketNum");
                            var spanTotalPriceDue=document.getElementById("spanTotalPriceDue");
                           
                            spanTotalOrderCount.innerText=PNRList.length;
                            spanRRCount.innerText=PNRList.length-noRRCount;
                            spanNoRRCount.innerText=noRRCount;
                            spanTotalTicketNum.innerText=totalTicketNum;
                            spanTotalPriceDue.innerText=totalPriceDue.toFixed(2);  */ 这块是自定义
                          }
                            checkStatus();//当返回结果时,继续下一次取数组的值,继续调用webservice
                       }
                  }    
             }//end httpRequest.onreadystatechange
            httpRequest.open("post", "IBEServiceGetPnrStatusByPNR.asmx/GetPNRStatusFromPNR", true);
            httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            httpRequest.send("PNR="+PNRList[currentIndex]);
          
        }  
    }

   StartCheckPNRStatus();

</script>--在页面加载完毕后  执行这个调用webservice的方法

也可以使用定时器来定时调用webservice

 


  

 

转载于:https://www.cnblogs.com/Tiffany_2008/archive/2009/06/11/1501576.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值