我從.NET應用程序調用經典ASP Webservices。我有兩個緩慢的Web服務處理和快速處理的實例。我需要加快我的.NET webservice調用經典ASP webservices
較慢的方式(幾秒鐘最多),是我竟讀這樣返回的數據:
Dim oRequestAOCP As WebRequest
Dim oResponseAOCP As HttpWebResponse = Nothing
Dim dataStreamAOCP As Stream = Nothing
Dim readerAOCP As StreamReader = Nothing
Dim responseFromServerAOCP As String
Dim sAOCP = Session("SecureURL") & "/services/rtOrderEntryAOCP.asp"
sAOCP = sAOCP & "?coskey=" & Server.UrlEncode(Session("GUID"))
sAOCP = sAOCP & "&OrderID=" & Server.UrlEncode(Session("OrderID"))
oRequestAOCP = WebRequest.Create(sAOCP)
oRequestAOCP = CType(oRequestAOCP, HttpWebRequest)
oRequestAOCP.Method = "GET"
oResponseAOCP = CType(oRequestAOCP.GetResponse(), HttpWebResponse)
dataStreamAOCP = oResponseAOCP.GetResponseStream()
readerAOCP = New StreamReader(dataStreamAOCP)
responseFromServerAOCP = readerAOCP.ReadToEnd()
Dim xmlAOCP As New XmlDocument()
xmlAOCP.LoadXml(responseFromServerAOCP)
Dim nodeAOCP As XmlNodeList = xmlAOCP.GetElementsByTagName("SUCCESS")
Dim valueAOCP = CBool(nodeAOCP(0).InnerText)
然後,下面是相當快的(亞秒),在這裏我只期望由於在大多數情況下需要從網絡服務返回數據,所以HTTP狀態將被返回而沒有其他東西 - 這不是一個好的MO。
Dim oRequest As WebRequest
Dim oResponse As HttpWebResponse = Nothing
Dim oEmail As New Email()
'now, call the webservice to get the AESBlock
Dim strUrl = Session("SecureURL") & "/services/rtOrderEntryStatusUpdate.asp"
strUrl = strUrl & "?GUID=" & Server.UrlEncode(Session("MISCGUID"))
strUrl = strUrl & "&Status=" & Server.UrlEncode(sStatus)
strUrl = strUrl & "&Error=" & Server.UrlEncode(sError)
'make the call to the webservice to prime the order
oRequest = WebRequest.Create(strUrl)
oRequest = CType(oRequest, HttpWebRequest)
oRequest.Method = "GET"
oResponse = CType(oRequest.GetResponse(), HttpWebResponse)
當我需要返回數據時,我能做些什麼來加快速度?
首先,您需要將響應,數據流和數據流讀取器放入使用塊中,以便將它們丟棄。這可能會影響性能。 – 2010-09-01 17:02:12
我將它們放在Try Catch的Finally塊中,我沒有將它包含在代碼片段中。 – crackedcornjimmy 2010-09-01 17:06:39