2010-09-01 78 views
1

我從.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) 

當我需要返回數據時,我能做些什麼來加快速度?

+0

首先,您需要將響應,數據流和數據流讀取器放入使用塊中,以便將它們丟棄。這可能會影響性能。 – 2010-09-01 17:02:12

+0

我將它們放在Try Catch的Finally塊中,我沒有將它包含在代碼片段中。 – crackedcornjimmy 2010-09-01 17:06:39

回答

1

研究多一些這種方案後。 System.Net.WebClient可能會提供解決方案。至少對於我使用的示例來說,看起來非常快。你可以嘗試一下,看看它是否縮短了一些時間。

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")) 

    Dim objWebClient As New WebClient 

    dataStreamAOCP = objWebClient.OpenRead(sAOCP) 
    readerAOCP = New StreamReader(dataStreamAOCP) 
    responseFromServerAOCP = readerAOCP.ReadToEnd() 

    Dim xmlAOCP As New XmlDocument() 
    xmlAOCP.LoadXml(responseFromServerAOCP) 
    Dim valueAOCP = CBool(xmlAOCP.SelectSingleNode("//SUCCESS").InnerText) 
+0

我會研究它。謝謝! – crackedcornjimmy 2010-10-06 13:23:36

0

看不到還有什麼可以做的,以削減幾秒鐘。我唯一能想到的就是直接從XML文檔中獲取valueAOCP。我認爲這裏的性能主要是響應大小的一個因素,因爲所有其他事情與其他Web服務相同。因此,如果能夠做到這一點,請考慮減少響應的大小。


Dim xmlAOCP As New XmlDocument() 
xmlAOCP.LoadXml(responseFromServerAOCP) 
Dim valueAOCP = CBool(xmlAOCP.SelectSingleNode("//SUCCESS").InnerText) 
+0

當然。我明白那個。但是,這個響應返回的唯一結果是「True」或「False」。而已。沒有其他的。 – crackedcornjimmy 2010-10-04 18:23:46