I need to speed up my .NET webservice calls to Classic ASP webservices
I am calling Classic ASP Webservices from a .NET application. I have two instances of slow processing of the webservice and fast processing.
The slow way (several seconds at the most) is where I actually read the data returned as such:
Dim oRequestAOCP As WebRequest
Dim oResponseAOCP As HttpWebResponse = Nothing
Dim dataStreamAOCP As Stream = Nothing
Dim readerAOCP As StreamReader = Nothing
Dim respo开发者_开发问答nseFromServerAOCP 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)
Then, the following is quite fast (sub-second), where I only expect the HTTP status to be returned and nothing else - not a good MO, due to needing data back from webservices in most cases.
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)
What can I do to speed things up when I need data returned?
After researching some more on this scenario. System.Net.WebClient may give the solution. Looks very fast to me at least for the sample example that I used. You can give it a try and see if it cuts down some time.
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)
Can't see what else you can do to shave off some seconds. The only thing I can think of is to get valueAOCP directly from the XML document. I think the performance here is mainly a factor of the response size since all other things are the same with the other web service. So consider reducing the size of the response if it is within your power to do so.
Dim xmlAOCP As New XmlDocument()
xmlAOCP.LoadXml(responseFromServerAOCP)
Dim valueAOCP = CBool(xmlAOCP.SelectSingleNode("//SUCCESS").InnerText)
精彩评论