I am using WebServiceCallout.invoke inside a batch to call a SOAP webservice in Dynamics AX. The batch size is 1. What I am seeing: after 9 or 10 fast (1 second) and successful callouts, the next one fails with an error message:

The request channel timed out while waiting for a reply after 00:01:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.

After that, 9 or 10 fast and successful callouts, and then another timeout. Etcetera, etcetera.

The problem is not with the request per se: if I fire it individually, it returns data in 1 second.

The timeout for WebServiceCallout.invoke is set to 2 minutes. The Dynamics people are reluctant to increase the timeout on their side and I think I agree with them that it will not solve the problem. The callout will probably still timeout and not return data. They ask: are you closing your connections?

I don't know, I just use WebServiceCallout.invoke. It's the only method in the WebServiceCallout class. Also, I can't find a way to pass options to invoke that have something to do with closing. Anybody seen this before? Any ideas?

2 Answers 2


You can try do create a HTTP Callout. One of the methods of the methods of the HTTPRequest class is the setTimout(Integer timeout) that allows you to set the time out. That could also let you handle the time out exception.

public class HttpCalloutSample {

  // Pass in the endpoint to be used using the string url
  public String getCalloutResponseContents(String url) {

    // Instantiate a new http object
    Http h = new Http();

     // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
    HttpRequest req = new HttpRequest();
    req.setTimeOut(3000); //3s (The timeout can be any value between 1 and 120,000 milliseconds)

    // Send the request, and return a response
        HttpResponse res = h.send(req);
        return res.getBody();
    }catch(Exception e){
        //handle timeout exception
  • WebServiceCallout.invoke has an option to set a timeout. It's set to 2 minutes. I added it to my question, I had forgotten. The timeout error is generated by the server. Aug 25, 2016 at 6:04

This turned out to be a problem with the other side.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .