Developer forum

Forum » Integration » Increase timeout for endpoint?

Increase timeout for endpoint?

Anders Ebdrup
Anders Ebdrup
Reply

Dear Dynamicweb,

 

I need to increase the timeout for one of our endpoints, as we see this issue: "Error occured when executing endpoint 3: The operation has timed out".

How can we increase the timeout?

 

Best regards, Anders


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Anders,
Let me figure out the context of your problem. Are you running it from the scheduled task with some intervals?
Is it run manually from the schedeuled task list?
How long does it take when the exception is occured? 30min, 1hr, 2hr, etc?
Could this be a case when your server receives the first long processing request and is producing the response while your second request arrives and gets a timeout error because of the first request still not processed?
BR, Dmitrij

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Dmitrij,

This is the result when I try to run the activity manually:

2021-08-18 21:08:34.441: Starting scheduled task.
2021-08-18 21:08:34.488: Request: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">     <s:Body>         <GetCustomers_V2 xmlns="http://iWebService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">             <WebserviceLogonData>                     </WebserviceLogonData>             <FullDataset>true</FullDataset>         </GetCustomers_V2>     </s:Body> </s:Envelope>.
2021-08-18 21:10:14.523: Error occured when executing endpoint 3: The operation has timed out
2021-08-18 21:10:14.523: Response: .
2021-08-18 21:10:14.523: Xml returned from the web service: '' is empty

 

My guess is that we see the default timeout as seen here: https://docs.microsoft.com/en-us/dotnet/api/system.net.webrequest.timeout?view=net-5.0

 

Best regards,

Anders

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Can you try to test it with this one where the Timeout is set to Infinite?

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Dmitrij,

 

Thanks for quick response here! :-D

But is is not working:


[ActivationException: Dynamicweb.Core.IApplicationAssembly LoaderExceptions information: Method 'GetMode' in type 'Dynamicweb.DataIntegration.Providers.EndpointProvider.EndpointProvider' from assembly 'Dynamicweb.DataIntegration.Providers.EndpointProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. ]
 

Best regards,

Anders

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Anders,
then you need to download the last version of EndpointProvider from here.
BR, Dmitrij

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Dmitrij,

 

Thanks the solution is now working, but I still see the timeout. I have used dotpeek and cannot see, where the timeout has been increased, but maybe I am looking at the wrong place?

 

private HttpWebRequest GetRequest(Endpoint endpoint, string requestBody)
    {
      Uri uri = this.GetUri(endpoint.FullUrl);
      HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(uri);
      EndpointAuthentication endpointAuthentication = (EndpointAuthentication) null;
      if ((uint) endpoint.AuthenticationId > 0U)
        endpointAuthentication = new EndpointAuthenticationService().GetEndpointAuthenticationById(endpoint.AuthenticationId);
      if (endpointAuthentication != null && (uint) endpointAuthentication.Type > 0U)
      {
        if (endpointAuthentication.Type != EndpointAuthenticationType.OAuth2)
        {
          NetworkCredential networkCredential = endpointAuthentication.GetNetworkCredential();
          httpWebRequest.Credentials = (ICredentials) new CredentialCache()
          {
            {
              uri,
              endpointAuthentication.GetAuthType(),
              networkCredential
            }
          };
        }
        else
        {
          string token = OAuthHelper.GetToken(endpointAuthentication);
          httpWebRequest.Headers.Add("authorization", "Bearer " + token);
        }
      }
      httpWebRequest.Method = endpoint.RequestType.ToString();
      if (endpoint.Headers != null)
      {
        foreach (string key in (IEnumerable<string>) endpoint.Headers.Keys)
        {
          if (!((IEnumerable<string>) this.ContentTypeKeyNames).Contains<string>(key.ToLower()))
            httpWebRequest.Headers.Add(key, endpoint.Headers[key]);
          else
            httpWebRequest.ContentType = endpoint.Headers[key];
        }
      }
      string str = requestBody != null ? requestBody : endpoint.Body;
      if (!string.IsNullOrEmpty(str))
      {
        using (Stream requestStream = httpWebRequest.GetRequestStream())
        {
          using (StreamWriter streamWriter = new StreamWriter(requestStream))
            streamWriter.Write(str);
        }
      }
      httpWebRequest.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(EndpointService.ValidateRemoteCertificate);
      return httpWebRequest;
    }

 

Best regards, Anders

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Anders,
it is here (method above the yours from the stack):
method: public virtual string Execute(int endpointId, string requestBody)
HttpWebRequest request = GetRequest(endpoint, requestBody);
request.Timeout = Timeout.Infinite;
BR, Dmitrij

 
Anders Ebdrup
Anders Ebdrup
Reply

Allright, but it is not working...

 

I doesn't you make the call here:

 

    private HttpWebRequest GetRequest(Endpoint endpoint, string requestBody)
    {
      Uri uri = this.GetUri(endpoint.FullUrl);
      HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(uri);
      EndpointAuthentication endpointAuthentication = (EndpointAuthentication) null;
      if ((uint) endpoint.AuthenticationId > 0U)
        endpointAuthentication = new EndpointAuthenticationService().GetEndpointAuthenticationById(endpoint.AuthenticationId);
      if (endpointAuthentication != null && (uint) endpointAuthentication.Type > 0U)
      {
        if (endpointAuthentication.Type != EndpointAuthenticationType.OAuth2)
        {
          NetworkCredential networkCredential = endpointAuthentication.GetNetworkCredential();
          httpWebRequest.Credentials = (ICredentials) new CredentialCache()
          {
            {
              uri,
              endpointAuthentication.GetAuthType(),
              networkCredential
            }
          };
        }
        else
        {
          string token = OAuthHelper.GetToken(endpointAuthentication);
          httpWebRequest.Headers.Add("authorization", "Bearer " + token);
        }
      }
      httpWebRequest.Method = endpoint.RequestType.ToString();
      if (endpoint.Headers != null)
      {
        foreach (string key in (IEnumerable<string>) endpoint.Headers.Keys)
        {
          if (!((IEnumerable<string>) this.ContentTypeKeyNames).Contains<string>(key.ToLower()))
            httpWebRequest.Headers.Add(key, endpoint.Headers[key]);
          else
            httpWebRequest.ContentType = endpoint.Headers[key];
        }
      }
      string str = requestBody != null ? requestBody : endpoint.Body;
      if (!string.IsNullOrEmpty(str))
      {
        using (Stream requestStream = httpWebRequest.GetRequestStream())
        {
          using (StreamWriter streamWriter = new StreamWriter(requestStream))
            streamWriter.Write(str);
        }

      }
      httpWebRequest.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(EndpointService.ValidateRemoteCertificate);
      return httpWebRequest;
    }

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

I have put the code 
request.Timeout = Timeout.Infinite;
in the method
Dynamicweb.DataIntegration.EndpointManagement.EndpointService.Execute(int endpointId, string requestBody)
which is calling this:
HttpWebRequest request = GetRequest(endpoint, requestBody);
request.Timeout = Timeout.Infinite;
using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        result = GetResponseContent(response, request.Headers, soapHeaderKey);
                    }

BR, Dmitrij

 
Anders Ebdrup
Anders Ebdrup
Reply

Yes, and it is not wokring - we still see this:

 

2021-08-19 09:26:24.155: Starting scheduled task.
2021-08-19 09:26:24.374: Request: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">     <s:Body>         <GetCustomers_V2 xmlns="http://iWebService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">             <WebserviceLogonData>                 <FirmaNo>1</FirmaNo>                 <ServiceUserNm>1stWeb</ServiceUserNm>                 <ServicePassword>KaffeR#1</ServicePassword>             </WebserviceLogonData>             <FullDataset>true</FullDataset>         </GetCustomers_V2>     </s:Body> </s:Envelope>.
2021-08-19 09:28:04.402: Error occured when executing endpoint 3: The operation has timed out
2021-08-19 09:28:04.402: Response: .
2021-08-19 09:28:04.402: Xml returned from the web service: '' is empty

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

I've added request.ReadWriteTimeout = Infinite
Can you try with this version?
If that does not work can you send me your endpoint setup by email so I can try to reproduce it locally?

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Dmitrij,

 

Thanks again, but this is now the result:

2021-08-19 11:24:28.859: Starting scheduled task.
2021-08-19 11:24:29.015: Request: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">     <s:Body>         <GetCustomers_V2 xmlns="http://iWebService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">             <WebserviceLogonData>                 <FirmaNo>1</FirmaNo>                 <ServiceUserNm>1stWeb</ServiceUserNm>                 <ServicePassword>KaffeR#1</ServicePassword>             </WebserviceLogonData>             <FullDataset>true</FullDataset>         </GetCustomers_V2>     </s:Body> </s:Envelope>.
2021-08-19 11:24:29.030: Error occured when executing endpoint 3: This operation cannot be performed after the request has been submitted.
2021-08-19 11:24:29.030: Response: .

 

Can you fix for problem before sending the setup?

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Can you send me your endpoint setup(url, settings, authentication, etc) by email so I can try to reproduce it locally?

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Anders,
this issue has been fixed in the DataIntegration package 3.0.19 version.
BR, Dmitrij

Votes for this answer: 1

 

You must be logged in to post in the forum