特定的Web服务需要大量时间来响应! [英] Specific Web Service takes huge time to respond !!

查看:88
本文介绍了特定的Web服务需要大量时间来响应!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我可以访问用PHP编写的简单Web服务,该服务将返回客户端的IP地址.我正在使用HttpWebRequest&在C#应用程序中使用此WS. HttpWebResponse.该WS需要很长的时间才能收到来自服务器的回复.实际上,根据服务器日志,它也可以从服务器快速返回,但是到我的客户端接收到它时,时间就在那上面.

我在我的应用程序中访问了WS 4-5次,并且由于这种延迟而提起诉讼,我的客户花了一些时间才能实现目标.我也从同一台服务器上使用其他WS,它工作得很好.

任何人都可以帮助我确定问题出在哪里-在Server或Cleint上.延迟特定WS响应的问题可能是什么.

注意:我为使用的所有WS调用相同的函数从服务器发送/接收响应.我有日志和客户代码.


Hello,

I have access to a simple WebService written in PHP that returns the IP address of the Client. I am using this WS in my C# application using HttpWebRequest & HttpWebResponse. This WS takes a long tiem to receive the reply from server. Actually according to server logs, it returns fast from server also, but by the time my client receives it, time is occupied over there.

I am accessing this WS 4-5 times in my application and sue to this delay in response my client takes time to accomplish the goal. I use other WS''s also from the same server and it works perfectly fine.

Can anyone help me identify where must be the problem - on Server or Cleint. What can be the problem that delays response for specific WS.

NOTE : I call same function to send/receive response from the server for all WS''s that I use. I have the logs & code of the client.


public static string getPublicIP(String host)
{
     string post_data = "cmd=ipcheck";
     string uri = "https://" + host;

     String responseData = "";

     CommonUtilities.WriteLog("Into getPublicIP(host)... URI = " + uri);
     try
     {
       CommonUtilities.WriteLog("Into getPublicIP(host)...CALLING SENDPOST.");
       // Performs POST on uri & post_data
       responseData = SendPost(uri, post_data);
       CommonUtilities.WriteLog("Into getPublicIP(host)...RCVD RESPONSE");
       responseData = responseData.Trim();
       if (responseData.Length <= 0)
          throw new Exception("No response received from Server for IP Check");
     }
     catch (Exception e)
     {
         Console.WriteLine("********* Excp in getPublicIP MSG - " + e.Message);
         Console.WriteLine("INNER EXcep = " + e.InnerException);
         throw new Exception(e.Message, e.InnerException);
     }

     int start = responseData.Contains("<ip>") ? responseData.IndexOf("<ip>") +4 : -1;
     int end = responseData.Contains("</ip>") ? responseData.IndexOf("</ip>") : -1;
     string data = String.Empty;

     if (start != -1 && end != -1)
     {
        data = responseData.Substring(start, end - start);
     }
     CommonUtilities.WriteLog("Into getPublicIP(host)...DATA RETURNED = " + data);
     return data;
}

        private static String SendPost(String uri, String post_data)
        {
            String resData = "";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";

            // turn request string into byte[]
            byte[] postBytes = Encoding.ASCII.GetBytes(post_data);

            Stream requestStream = null;

            try
            {
                // Send it
                request.ContentLength = postBytes.Length;
                CommonUtilities.WriteLog("Request URL = " + request.RequestUri.ToString() + " DATA = " + post_data);
                requestStream = request.GetRequestStream();
                requestStream.Write(postBytes, 0, postBytes.Length);
                CommonUtilities.WriteLog("INTO SendPost: REQUEST SEND SUCCESSFULLY");
            }
            catch (WebException we)
            {
               // .......
            }
            finally
            {
                if (requestStream != null)
                    requestStream.Close();
            }

            // Get the response
            HttpWebResponse response = null;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
                if (response == null)
                    return "";
                CommonUtilities.WriteLog("INTO SendPost: GOT RESPONSE");
                StreamReader sr = new StreamReader(response.GetResponseStream());
                resData = sr.ReadToEnd().Trim();
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Excep THROWN From SendPost 'GET' try block");
                throw new Exception("Error receiving response from POST : " + e.Message, e.InnerException);
            }
            finally
            {
                if (response != null)
                    response.Close();
            }
    
            return resData;
        }        



日志:



LOGS :

12-03-2012 15:22:39:815 ==> INFO : Calling getPublicIP from FORM...
12-03-2012 15:22:39:817 ==> INFO : Into getPublicIP(host)... 
12-03-2012 15:22:39:817 ==> INFO : Into getPublicIP(host)...CALLING SENDPOST.
12-03-2012 15:22:40:744 ==> INFO : INTO SendPost: REQUEST SEND SUCCESSFULLY
12-03-2012 15:22:41:422 ==> INFO : INTO SendPost: GOT RESPONSE
12-03-2012 15:22:41:424 ==> INFO : Into getPublicIP(host)...RCVD RESPONSE
12-03-2012 15:22:41:425 ==> INFO : Into getPublicIP(host)...DATA RETURNED = 

......
12-03-2012 15:23:34:387 ==> INFO : Checking Connectivity...
12-03-2012 15:23:34:389 ==> INFO : Into getPublicIP(host)... 
12-03-2012 15:23:34:390 ==> INFO : Into getPublicIP(host)...CALLING SENDPOST.
12-03-2012 15:23:51:230 ==> INFO : INTO SendPost: REQUEST SEND SUCCESSFULLY
12-03-2012 15:23:53:423 ==> INFO : INTO SendPost: GOT RESPONSE
12-03-2012 15:23:53:424 ==> INFO : Into getPublicIP(host)...RCVD RESPONSE
12-03-2012 15:23:53:426 ==> INFO : Into getPublicIP(host)...DATA RETURNED = 



在一个阶段,呼叫发送"和呼叫发送"之间的区别RCVD响应时间最长为15秒.这是第二次发送请求的SendPost()中的第二次巨大差异的原因.
请尽早帮助我.延迟会影响应用程序的性能,从而影响我的性能.

任何帮助都将受到高度赞赏.谢谢.



At a stage the difference between CALLING SENDPOST & RCVD RESPONSE is upto 15secs. What can be the reason the 2nd time huge difference in SendPost() for sending the request.

Please try to help me out at the earliest. The delay is affecting the performance of the application which is affecting my performance.

Any help is highly appreciated. Thanks.

推荐答案

您需要在服务端而不是客户端进行调查.您可能需要在服务中进行日志记录和跟踪,以了解花费了这么多时间到底是什么.
You need to investigate on the service end rather than the client. You may need to put in logging and tracing in the services to see what exactly is taking this much time.


我刚刚添加了
I just added
request.Proxy = null;



这确实神奇了.它可能正在寻找代理(自动检测).只是一个奇怪的问题:这种自动检测代理为什么只在此WS而不是在其他WS ????

但是无论如何,这对我来说很有效.

谢谢大家.



and this did the magic. It might be looking for proxy (auto-detecting). Just 1 wonder : how come this auto-detecting proxy is looking only for this WS and not for others ????

But anyways, this worked out for me.

Thanks to all of you.


这篇关于特定的Web服务需要大量时间来响应!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆