Metro2.0とJ2SE5を使用しています。私が作成したアプリケーションは、コンパイル時に外部WebServiceについて認識していません。実行時に、ビジネスロジックXMLファイルに基づいて外部Webサービスを検出するため、WSDL要求を実行します。
私が書いたサンプルコードは次のとおりです。
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");
// Create service and the dispatcher for the SOAP message
Service service = Service.create(new URL(wsdlURL), serviceName);
dispatch = service.createDispatch(servicePort, SOAPMessage.class, Service.Mode.MESSAGE);
// Set timeouts
dispatch.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 3000);
dispatch.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", 3000);
// Create the outgoing SOAP request
SOAPBinding soapBinding = (SOAPBinding) dispatch.getBinding();
request = soapBinding.getMessageFactory().createMessage();
SOAPBody requestBody = request.getSOAPBody();
requestBody.addDocument(payload);
// Invoke web service operation
SOAPMessage response = dispatch.invoke(request);
Webサービスが呼び出されると、タイムアウトは正しく機能します(dispatcher.invoke(request))
ただし、タイムアウトが設定される前にWSDLが要求され、Webサービスが応答しない場合は、接続がタイムアウトになるまでに90秒かかります。
WSDLが要求される前にタイムアウトを設定することは可能ですか?タイムアウトを設定するにはディスパッチャが必要ですが、WSDLを要求するサービスが作成された後に実行されますか?!(つまり、Service.create())