与我作为 Windows 应用程序运行时相比,WebMethod() 每次执行都很慢

发布于 2024-10-21 16:49:42 字数 7975 浏览 9 评论 0原文

我开发了一个与 IBM ClearQuest 交互的应用程序。问题是,当我在本地运行所有内容时,例如,在本地运行 Web 服务,然后在本地运行 ASP 页面,一切都按照我预期的速度进行。当我将 Web 服务(预编译)发布到服务器并通过服务器运行网页时,对 Web 方法的调用至少花费了应有时间的 10 倍。我不知道为什么会发生这种情况。我制作了一个控制台应用程序,该应用程序具有相关功能,并在服务器和本地执行它,它们都返回相同的时间(大致),就在我通过 webmethod 执行时,一切都进展缓慢。有什么想法吗?这种情况每次都会发生,而不仅仅是第一次通话时。

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 = colValue
                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

本地 Windows 应用程序方法:

    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();



    }

代码应在大约...6 秒内执行。

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 = colValue
                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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-10-28 16:49:42

通常这样的事情可以归结为权限问题。例如,Web 服务是否需要匿名用户,或者是否使用 Windows 身份验证。这也会影响网站。所以我会开始调查这一点。

无论如何,我强烈建议您将代码发布到 https://codereview.stackexchange.com/ 您可能会收到一些反馈关于如何更好地构建你所做的事情。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文