Im using Metro 2.0 and J2SE5. The application that I wrote does not know about the external WebService at compile time, it finds them at runtime based on the XML business logic file, so I execute the WSDL request.
The sample code I wrote is as follows:
String wsdlServiceName = ...;
String wsdlURL = ...;
Document payload = ...;
final String nsURI = ...;
final QName serviceName = new QName(nsURI, wsdlServiceName + "Service");
final QName servicePort = new QName(nsURI, wsdlServiceName + "Port");
Service service = Service.create(new URL(wsdlURL), serviceName);
dispatch = service.createDispatch(servicePort, SOAPMessage.class, Service.Mode.MESSAGE);
dispatch.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 3000);
dispatch.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", 3000);
SOAPBinding soapBinding = (SOAPBinding) dispatch.getBinding();
request = soapBinding.getMessageFactory().createMessage();
SOAPBody requestBody = request.getSOAPBody();
requestBody.addDocument(payload);
SOAPMessage response = dispatch.invoke(request);
code>
Timeout works correctly when calling a web service (dispatcher.invoke (request))
HOWEVER, if a WSDL request is requested before the timeout expires, and if the web service does not respond, then 90 seconds before the connection timeout.
Is it possible to set timeouts before a WSDL request? You need a dispatcher to set timeouts, but this is done AFTER creating a service that requests WSDL ?! (i.e. Service.create ())