+ Start a Discussion
SFDC coderSFDC coder 

Error:Read timeout Exception during apex callouts

Hi all,

I have an apex callouts class taht invokes an external webservice.We have been using the SOAP API.
So i have imported the wsdl in salesforce and trying to invoke the autogenerated apex class.
However i get an error as:Read timeout Exception

Then i try to set the timeout as under and then invoke the webservice as below:
public class OrderCallOuts
{

    @future(callout=true)
    public static void sendOrders(String orderId)
    {
      try
      {
          
          //creating stub
          SfdcDirectordersinbound.MIOS_SFDC_DIRECT_ORDERPort  createOrder=new  SfdcDirectordersinbound.MIOS_SFDC_DIRECT_ORDERPort();
        
          //declaring the response element
          String callOutResponse='';
       
           // providing the credentials and setting the header
           createOrder.inputHttpHeaders_x=new Map<String,String>();
           String username = 'salerep1';
           String password = 'Pass_1235';  
           Blob headerValue = Blob.valueOf(username+':'+password);
           String authorizationHeader = 'Basic ' +EncodingUtil.base64Encode(headerValue);
           createOrder.inputHttpHeaders_x.put('Authorization',authorizationHeader);

          //setting the timeout           
          createOrder.timeout_x=120000;
           
          //Invoking the webservice to send orders from Salesforce  
          callOutResponse=createOrder.MIOS_SFDC_DIRECT_ORDER(myOrder.CreatedBy.name,myOrder.LastModifiedBy.name);
                                                
          System.debug('Response from SAP system:'+callOutResponse);
     }
     catch(Exception ex)
     {
         System.debug('*** Error'+ex);
     }     
    }
    
}


After executing the above code i get the below error:
*** ErrorSystem.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Server Error faultcode=SOAP:Server faultactor=

Can anyone please help?

Thanks
Best Answer chosen by SFDC coder
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@SFDC Coder:

Hi,
  Since you set the maximum time out, salesforce will wait 120K milli seconds for the result to be returned by the service that you were consuming. Since that service is not able to return in time, you were being timed out. This has nothing to do with Salesforce side service rather i would recommend checking with the person who published the service to see if he can imporve his codes  performance so that the output will be returned before the timeout happens.

 I have been through this issue before mainly with .net services which we consumed, their queries/store procs were taking too long to be run, after too much back and forth, the developer for that .net service accepted and tweaked his queries which improved the response time and it never got errored out later that.

Hope this helps:

Thanks,
balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati
@SFDC Coder:

Hi,
  Since you set the maximum time out, salesforce will wait 120K milli seconds for the result to be returned by the service that you were consuming. Since that service is not able to return in time, you were being timed out. This has nothing to do with Salesforce side service rather i would recommend checking with the person who published the service to see if he can imporve his codes  performance so that the output will be returned before the timeout happens.

 I have been through this issue before mainly with .net services which we consumed, their queries/store procs were taking too long to be run, after too much back and forth, the developer for that .net service accepted and tweaked his queries which improved the response time and it never got errored out later that.

Hope this helps:

Thanks,
balaji
This was selected as the best answer
SFDC coderSFDC coder
thanks balaji...its exactly what was going wrong in our case as well...they did some modifications at their end and now its working.. :)
Satish PrajapatSatish Prajapat
Hello All,
Please refer the below code:
 
​HttpRequest req = new HttpRequest();
req.setEndpoint('Your url which you want to hit.');
req.setMethod('POST');
req.setBody('Body');//When I added this tag than I removed the 'read time out error.'
HttpResponse response = new Http().send(req);

Enjoy my DOST...!!!!!