我从.NET应用程序调用Classic ASP Webservices。我有两个缓慢处理Web服务和快速处理的实例。
缓慢的方式(最多几秒)是我实际读取返回的数据的地方:
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,因为在大多数情况下需要从webservices返回数据。
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 :(得分: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)
答案 1 :(得分:0)
看不出你还能做些什么来刮掉几秒钟。我唯一能想到的是直接从XML文档中获取valueAOCP。我认为这里的性能主要是响应大小的一个因素,因为所有其他事情与其他Web服务相同。因此,如果能够做到这一点,请考虑减小响应的大小。
Dim xmlAOCP As New XmlDocument()
xmlAOCP.LoadXml(responseFromServerAOCP)
Dim valueAOCP = CBool(xmlAOCP.SelectSingleNode("//SUCCESS").InnerText)