Set timeout on Web Service proxy generated by Flex Builder

Flex Builder has a pretty nifty WSDL tool to generate support classes to access a Web Service.
Some of the code generated looks rather sloppy though, but then that is the case with most code generation tools.

One glaring omission seems to be that there is no way to set a request timeout when using the Service class generated.
What further adds to confusion is that the underlying Service class in fact extends mx.rpc.AbstractWebService and hence mx.rpc.AbstractService which has a requestTimeout property. Setting that property has no effect however.

To set a timeout on the request, you need to modify the Flex Builder generated class.

Find the method that actually makes the call to the remote server, and set the requestTimeout value on the AsyncRequest being created

private function call(operation:WSDLOperation, args:Object, token:AsyncToken, headers:Array=null):void
  var enc:SOAPEncoder = new SOAPEncoder();
  var inv:AsyncRequest = new AsyncRequest();    
  inv.requestTimeout = _asyncRequestTimeout;

And add an asyncRequestTimeout property to the service class

private var _asyncRequestTimeout:int;
public function set asyncRequestTimeout(asyncRequestTimeout:int):void        
  _asyncRequestTimeout = asyncRequestTimeout;        

You could also use the asyncRequest property in AbstractService instead of creating your own property, but this way if somebody overwrites the generated class without adding these changes, the compiler will flag it as an error.
And a compile time error is always better than a runtime bug, isn’t it?