亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

怎樣在asp下使用WebService?

怎樣在asp下使用WebService?

慕姐4208626 2019-02-14 14:10:50
[WebMethod]public string MobilePhone(string mobile,string mobilePwd){if (mobile == null || mobilePwd.Length != 11)return "你輸入的有誤??!";string st = mobile.Substring(0, 2);if (st != "13" || st != "15" || st != "18" || st != "19")return "手機號的長度不夠!!";if (mobilePwd != "123456")return "NO";return "YES";}// 在ASP下我是這么寫的?。?!我在index.aspx頁上有兩個文本控件。localhost.WebService5 lw = new localhost.WebService5();string strMobilePhone = TextBox7.Text.Trim().ToString();string strPwd = TextBox8.Text.Trim().ToString();lw.MobilePhone(strMobilePhone, strPwd);-----》 怎么不好用呢 ??
查看完整描述

2 回答

?
蝴蝶刀刀

TA貢獻1801條經驗 獲得超8個贊

 方法如下:

  1、在項目中新建 Web 服務;


  2、WebService的后臺cs文件中,修改代碼如下;


  3、到Login.aspx的后臺cs代碼中,添加如下代碼;

  4、使用Web服務命名空間來調用其類和方法;

  5、隨意輸入用戶名和密碼,已經實現了驗證功能;

  6;輸入正確的用戶和密碼,系統可以正常登錄。


查看完整回答
反對 回復 2019-03-07
?
慕容3067478

TA貢獻1773條經驗 獲得超3個贊

如果要用ASP來調用WevService,就一定要使用SOAP Toolkit或者XMLHTTP, 使用SOAP Client需要專門安裝SOAP Toolkit,這對客戶端來說不具有通用性,因此我們就學習使用XML來進行對WebService的調用。
<%
Set objHTTP = Server.CreateObject( "MSXML2.XMLHTTP ")
Set xmlDOC =Server.CreateObject( "MSXML.DOMDocument ")
strWebserviceURL = "http://localhost/WebService1/Service1.asmx/Add "
'設置參數和值
strRequest = "a=5&b=6 "
objHTTP.Open "POST ", strWebserviceURL, False
'設置Content-Type很重要
objHTTP.SetRequestHeader "Content-Type ", "application/x-www-form-urlencoded "
objHTTP.Send(strRequest)
bOK = xmlDOC.load(objHTTP.responseXML)
'查看狀態值
if objHTTP.Status=200 then
xmlStr = xmlDOC.xml
xmlStr = Replace(xmlStr, "< ", " < ",1,-1,1)
xmlStr = Replace(xmlStr, "> ", "> ",1,-1,1)
Response.Write xmlStr
else
Response.Write objHTTP.Statu& " <br> "
Response.Write objHTTP.StatusText
end if
%>
以上代碼在本地測試都沒有問題(在部署webservice的本地機器上測試的),然而把strWebserviceURL = "http://localhost/WebService1/Service1.asmx/Add "改為部署在其他機器上的WebService時,卻出了問題,結果一直是返回500錯誤,即objHTTP.Status一直都為500。
  原因在于.Net Framework1.1默認不支持HttpGet和HttpPost。如果修改webservice里的web.config增加上代碼5后,上代碼就可以調用遠程機器上的WebService了。

<webServices>
   <protocols>
     <add name= "HttpPost "/>
     <add name= "HttpGet "/>
   </protocols>
</webServices>



查看完整回答
反對 回復 2019-03-07
  • 2 回答
  • 0 關注
  • 767 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號