webservice响应时间增加了...怎么样?

时间:2011-12-15 18:43:45

标签: c# asp.net web-services

我有一个网络服务方法:

[WebMethod]
public Response Process()
{
   return RunCode();
}

RunCode()需要6秒才能运行,但IIS /浏览器需要20秒以上才能返回XML。

如果我把RunCode()放在一个线程中,它现在将在6秒后返回:

private _response Response;
[WebMethod]
public Response Process()
{
   new Thread(RunProcess).Start()
   while(_response==null)
   {
     Thread.Sleep(100);
   }
   return _response;
}

private void RunProcess()
{
   _response=RunCode();
}

我的问题是......在RunCode()中可能会发生什么来强制IIS / ASP.NET延迟响应?代码只需要6秒就可以运行......如果某种资源不在一个单独的线程上,它会被捆绑并锁定,所以ASP.NET会等待它吗?

编辑#1:请求了响应的示例。 答案的一个例子是:

<PostResponse>
      <isValidPost>false</isValidPost>
      <ResponseType>Post_Over_Max</ResponseType>
      <ResponseDetails>System is currently at max leads allowed</ResponseDetails>
      <LeadIdentifier>0</LeadIdentifier>
      <VendorAccountAssigned>0</VendorAccountAssigned>
      <PendingQCReview>false</PendingQCReview>
      <Price>0</Price>
      <RedirectURL/>
</PostResponse>

基于这个课程:

public class PostResponse : IPostResponse
{
    public PostResponse()
    {
    }

    public PostResponse(bool isValid, ResponseErrors responseType, string details, long leadIdentifier,
                        long vendorAccountAssigned, bool pendingQCReview, double price, string redirectUrl)
    {
        isValidPost = isValid;
        ResponseType = responseType;
        ResponseDetails = details;
        LeadIdentifier = leadIdentifier;
        VendorAccountAssigned = vendorAccountAssigned;
        PendingQCReview = pendingQCReview;
        Price = price;
        RedirectURL = redirectUrl;
    }

    #region IPostResponse Members

    public bool isValidPost { get; set; }
    public ResponseErrors ResponseType { get; set; }
    public string ResponseDetails { get; set; }
    public long LeadIdentifier { get; set; }
    public long VendorAccountAssigned { get; set; }
    public bool PendingQCReview { get; set; }
    public double Price { get; set; }
    public string RedirectURL { get; set; }

    #endregion
}

1 个答案:

答案 0 :(得分:0)

如果请求挂起,ASP.NET运行库将阻止来自同一用户会话的线程。

Why can’t I execute two requests from the same session simultaneously for an ASP.NET application?