WebMethod() is slow on each execution compared to when I run it as a windows application
I have developed an application that interacts with IBM ClearQuest. The problem is that when I run everything locally, such as, run the webservice local and then ASP page local everything is at the speed I expect. When I post the webservice (precompiled) to the server and run the web page through the server, the call to the webmethod takes at least 10x the amount of time it should. I dont know why this is happening. I made a console application that has the function in question and execute it on the server and locally and they both return the same amounts of time (roughly) its just when I move to executing via the webmethod everything grinds to a snails pace. Any ideas? This happens every time not just on the first call.
WebMethod:
Public Function RetrieveQueryResults(ByRef cqSession As ClearQuestOleServer.Session, _
ByVal sqlStmt As String) As List(Of SearchResultsSingleIssue)
Dim numCols As Integer, status As Integer, columnIdx As Integer
Dim numRows As Integer
Dim rowContents As String = ""
Dim colValue As New Object
Dim colLabel As New Object
Dim allitems As New List(Of SearchResultsSingleIssue)
Dim results As New SearchResultsSingleIssue
Dim cqResultSet As ClearQuestOleServer.OAdResultset
cqResultSet = cqSession.BuildSQLQuery(sqlStmt)
cqResultSet.Execute()
' Get the number of columns returned by the query.
numRows = 0
numCols = cqResultSet.GetNumberOfColumns
status = cqResultSet.MoveNext
' Collect query results.
Do While status = AD_SUCCESS
results = New SearchResultsSingleIssue
numRows = numRows + 1
For columnIdx = 1 To numCols
colLabel = cqResultSet.GetColumnLabel(columnIdx)
colValue = cqResultSet.GetColumnValue(columnIdx)
'Make sure that we dont pass along a null reference
If colValue = Nothing Then
colValue = ""
End If
Select Case colLabel
Case "ID"
results.IssueID = colValue
Case "HEADLINE"
results.Headline = colValue
Case "NAME"
results.State = colValue
Case "OE_CONTACT"
results.OEContact = colValue
Case "DESCRIPTION"
results.Further_Description = colValue
Case "PRODUCT_NAME"
results.Product_Name = colValue
Case "FUNCTIONAL_AREA"
results.Functional_Area = colVal开发者_开发知识库ue
Case "SUBTOPIC"
results.Subtopic = colValue
Case "FOUND_VERSION"
results.Found_In = colValue
Case "SCHEDULED_VERSION"
results.Scheduled_For = colValue
Case "SYMPTOMS"
results.Symptoms = colValue
Case "AFFECTED_SYSTEMS"
results.Affected_System_Types = colValue
Case "ISSUE_TYPE"
results.Issue_Type = colValue
Case "ASSIGNED_TO"
results.Assigned_Developer = colValue
Case "TESTED_BY"
results.Assigned_Tester = colValue
Case "BUILT_VERSION"
results.Built_In = colValue
Case "TESTED_VERSION"
results.Tested_In = colValue
Case "NOTES_LOG"
results.Notes_Log = colValue
Case "CUSTOMER_SEVERITY"
results.Severity = colValue
Case "PRIORITY"
results.Priority = colValue
End Select
Next columnIdx
' Add the query row result to the compiled list of all rows.
allitems.Add(results)
status = cqResultSet.MoveNext
Loop
Return allitems
End Function
Local Windows Application Method:
private void button2_Click(object sender, EventArgs e)
{
start = DateTime.Now.TimeOfDay.Seconds;
int numCols = 0;
int status = 0;
int columnIdx = 0;
int numRows = 0;
string rowContents = "";
string colValue;
string colLabel;
List<SearchResultsSingleIssue> allitems = new List<SearchResultsSingleIssue>();
SearchResultsSingleIssue results = new SearchResultsSingleIssue();
ClearQuestOleServer.OAdResultset cqResultSet = default(ClearQuestOleServer.OAdResultset);
cqResultSet = (ClearQuestOleServer.OAdResultset)ClearQuestSession.BuildSQLQuery(sqlStatement);
cqResultSet.Execute();
// Get the number of columns returned by the query.
numRows = 0;
numCols = cqResultSet.GetNumberOfColumns();
status = cqResultSet.MoveNext();
// Collect query results.
while (status == 1)
{
results = new SearchResultsSingleIssue();
numRows = numRows + 1;
for (columnIdx = 1; columnIdx <= numCols; columnIdx++)
{
colLabel = (string)cqResultSet.GetColumnLabel(columnIdx);
colValue = (string)cqResultSet.GetColumnValue(columnIdx);
//Make sure that we dont pass along a null reference
if (colValue == null)
{
colValue = "";
}
switch (colLabel)
{
case "ID":
results.IssueID = colValue;
break;
case "HEADLINE":
results.Headline = colValue;
break;
case "NAME":
results.State = colValue;
break;
case "OE_CONTACT":
results.OEContact = colValue;
break;
case "DESCRIPTION":
results.Further_Description = colValue;
break;
case "PRODUCT_NAME":
results.Product_Name = colValue;
break;
case "FUNCTIONAL_AREA":
results.Functional_Area = colValue;
break;
case "SUBTOPIC":
results.Subtopic = colValue;
break;
case "FOUND_VERSION":
results.Found_In = colValue;
break;
case "SCHEDULED_VERSION":
results.Scheduled_For = colValue;
break;
case "SYMPTOMS":
results.Symptoms = colValue;
break;
case "AFFECTED_SYSTEMS":
results.Affected_System_Types = colValue;
break;
case "ISSUE_TYPE":
results.Issue_Type = colValue;
break;
case "ASSIGNED_TO":
results.Assigned_Developer = colValue;
break;
case "TESTED_BY":
results.Assigned_Tester = colValue;
break;
case "BUILT_VERSION":
results.Built_In = colValue;
break;
case "TESTED_VERSION":
results.Tested_In = colValue;
break;
case "NOTES_LOG":
results.Notes_Log = colValue;
break;
case "CUSTOMER_SEVERITY":
results.Severity = colValue;
break;
case "PRIORITY":
results.Priority = colValue;
break;
}
}
// Add the query row result to the compiled list of all rows.
allitems.Add(results);
status = cqResultSet.MoveNext();
}
seconds = (DateTime.Now.TimeOfDay.Seconds - start);
label3.Text = seconds.ToString();
}
The code should execute in about...6 seconds.
Usually things like this boil down to problems in permissions. For example, is the web service expecting an anonymous user or is it using windows authentication. This would impact the web site as well. So I'd start looking into that.
Regardless, I would highly encourage you to post your code over at https://codereview.stackexchange.com/ You might get some feedback with regards to how better to structure what you've done.
精彩评论