vbs调用WebService -- 使用xmlhttp
生活随笔
收集整理的這篇文章主要介紹了
vbs调用WebService -- 使用xmlhttp
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
具體調用的代碼:
'向指定的文件寫入文本, 并指定是否是添加內容 Function Z_WriteFile(sFileName, sText, bAppend)Dim fs, fso, iomodeif bAppend = True Theniomode = 8 'ForAppendingelseiomode = 2 'ForWritingend ifset fs = CreateObject("Scripting.FileSystemObject")set fso = fs.OpenTextFile(sFileName, iomode, True) '第三個參數表明文件不存在,則新建文件fso.WriteLine sTextfso.Closeset fso = Nothingset fs = NothingZ_WriteFile = True End FunctionDim objHttp, xmlDoc, sText, sXml Set objHTTP = CreateObject("MSXML2.XMLHTTP") Set xmlDOC = CreateObject("MSXML.DOMDocument") strWebserviceURL = "http://192.168.2.39/webservice1/service.asmx/addition" strRequest = "i=2&j=3" objHTTP.Open "POST", strWebserviceURL, False objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" objHTTP.Send(strRequest)if objHTTP.Status = 200 ThenDim sNodeList, sResultxmlDOC.load(objHTTP.responseXML)set sNodeList = xmlDoc.getElementsByTagName("double")sResult = sNodeList(0).TextsText = "2+3=" & sResult elsesText = "調用WebService出錯,請檢查" end ifZ_WriteFile "ResultVoice.txt", sText, Falsewebservice是由vs.net2010(c#)開發的,核心代碼如下:
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 () {//如果使用設計的組件,請取消注釋以下行 //InitializeComponent(); }[WebMethod(Description = "Let's say \"Hello\"")]public string Hi(){return "Hello World, Happy New Year";}[WebMethod(Description = "Hello JoeBlack")]public string Hello(string username){return username + ", Happy New Year";}[WebMethod(Description = "求和的方法")]public double addition(double i, double j){return i + j;}[WebMethod(Description = "求差的方法")]public double subtract(double i, double j){return i - j;}[WebMethod(Description = "求積的方法")]public double multiply(double i, double j){return i * j;}[WebMethod(Description = "求商的方法")]public double division(double i, double j){if (j != 0)return i / j;elsereturn 0;}}為了讓WebService啟用對HttpGet和HttpPost協議的支持(默認配置只支持Soap協議),需要在WebService項目的Web.config中添加以下內容:
<system.web><!--設置 compilation debug="true" 可將調試符號插入已編譯的頁面中。但由于這會影響性能,因此請僅在開發過程中將此值設置為 true。--><compilation debug="true" targetFramework="4.0"></compilation><!--通過 <authentication> 節可以配置安全身份驗證模式,ASP.NET 使用該模式來識別來訪用戶身份。 --><!--配置WebService支持HttpPost和HttpGet協議--><webServices><protocols><add name="HttpPost" /><add name="HttpGet" /></protocols></webServices><authentication mode="Windows"/>運行下就可以看到處理后的結果,都寫入到了ResultVoice.txt文件中。
轉載于:https://www.cnblogs.com/joeblackzqq/archive/2011/03/01/1967748.html
總結
以上是生活随笔為你收集整理的vbs调用WebService -- 使用xmlhttp的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你相信这是XP经典桌面拍摄地现在的模样吗
- 下一篇: Blend设计VSM