GetRequestStream throws Timeout exception randomly

后端 未结 4 874
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 20:26

After googling for couple of days, I really cannot solve described issue. Hope here will find a solution

I\'m using attached code when calling WCF service on the sam

相关标签:
4条回答
  • 2020-12-09 20:59

    Because this is really strange behaviour I would like to know if there are any other ways to call WCF service, hosted on same IIS server. I also thing, that creating TCP connection for that kind of calls in not really optimized and all other approaches should be much faster.

    0 讨论(0)
  • 2020-12-09 21:11

    The first thing to keep in mind is to review the URI, parameters and headers being sent, specifically:

    • Reserved characters. Send reserved characters by the URI can bring problems ! * ' ( ) ; : @ & = + $ , / ? # []
    • URI Length: You should not exceed 2000 characters
    • Length headers: Most web servers do limit size of headers they accept. For example in Apache default limit is 8KB.

    Keep in mind that if you want to send data from a longer length is recommended to send in the body of the message.

    0 讨论(0)
  • 2020-12-09 21:15

    I had this same issue, adding a call to HttpWebRequest.Abort() seemed to fix it.

    0 讨论(0)
  • 2020-12-09 21:17

    I don't know that it's definitely responsible for the problem, but you're only closing the web response if it doesn't throw an exception, and you're never closing the response stream. Use using statements:

    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        return reader.ReadToEnd();
    }
    

    This could well explain the problem, as if you leave a response open it will keep the connection to the web server open - which means connection pooling then can't use that connection.

    0 讨论(0)
提交回复
热议问题