locked
Async HTTPS WebService - High time to get first response - Help RRS feed

  • Question

  • User-665281982 posted

    I need help.

    Why when I do the first call to a https webService async,  is having a high time to get response ?

    If I put more one call after this first call, the service async returns very fast.

    What I Have to do ? Is this any configuration in the server ? 

    The code is: 

    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    
    public static bool OnValidationCallback(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
            {
                return true;
            }
    
    public static bool InsertCustomer(IShopper customerData, ref string sCodErro)
            {
                
                try
                {
                    using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        if (!customerData.Insert())
                            return false;
    
                        if (!AppSettingsManager.GetValue("WcsCustomerSyncEnabled", true))
                        {
                            transactionScope.Complete();
                            return true;
                        }
    
                        ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnValidationCallback);
                        
                        var wcsCustomerSyncClient = new WcsCustomerSyncClient();
                        
                        try
                        {
                            
                            // I put this first call to test.. This gets high time to get response.
                            try
                            {
                                string ServerURL = "https://171.30.40.97:7854/TS/ECommCustomerSyncTSV2";
                                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ServerURL);
                                request.ContentType = "text/xml";
                                request.Method = "GET";
                                // Get the response
                                WebResponse response = null;
                                response = request.GetResponse();
                                
                            }
                            catch (Exception ex)
                            {
                                
                                
                            }
                            
                            //This is the main call in the method. This have to be the first call in the method. If continue the sencond call is very fast. 
                            var syncResponse = wcsCustomerSyncClient.submitCustomerSync(GetRequestData(OperationTypeType.I, customerData));
                            
    
                            
                        }
                        finally
                        {
                            wcsCustomerSyncClient.Abort();
                            wcsCustomerSyncClient.Dispose();
                        }
    
                        transactionScope.Complete();
                    }
                    return true;
                }
                catch (Exception ex)
                {
                    
                    return false;
                }
            }

    Friday, September 26, 2014 7:43 AM

Answers

  • User-417640953 posted

    Why when I do the first call to a https webService async,  is having a high time to get response ?

    If I put more one call after this first call, the service async returns very fast.

    Hi atiliosud,

    Thanks for your post.

    There many reasons caused the delay response of web service when the first request.

    # Web service needs start up on first call, after that, it will response quickly.

    You can configure IIS to have keepalive = true , I think that will improve the performance.

    # Some Serializer assemblies (.dll) need to be compiled on the firat request.

    To speed up the initial call you can create the XmlSerializers dll at compile time. You can do this by setting

    your project build 'Generate serialization assembly' to on.

    Please take a look at below similar thread and get more information:

    http://stackoverflow.com/questions/784918/asmx-web-service-slow-first-request

    http://stackoverflow.com/questions/16086045/first-call-to-a-net-webservice-is-slow

    Hope this helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 26, 2014 9:44 PM