views:

8

answers:

0

Which is more effective way of forming a WebService client out of the following ?

  1. Having the Service and Port objects of the generated Java artifacts (after importing the WSDL) as method-local objects. Example :
    public class TestWS {
    ...
    private void testLocal() {
    wsdlImportedPackage.TargetService localService = new wsdlImportedPackage.TargetService();
    wsdlImportedPackage.TargetServicePort localPort = localService.getTargetServicePort();
    wsdlImportedPackage.TargetResponse response = localPort.invoke();
    ...
    }
    }
  2. Having the Service and Port objects of the generated Java artifacts as static global. Example :
    public class TestWS {
    ...
    wsdlImportedPackage.TargetService globalService = null;
    wsdlImportedPackage.TargetServicePort globalPort = null;
    static {
    globalService = new wsdlImportedPackage.TargetService();
    globalPort = globalService.getTargetServicePort();
    }
    private void testGlobal() {
    wsdlImportedPackage.TargetResponse response = globalPort.invoke();
    ...
    }
    }

When the testLocal() method is load tested, it is observed that the code localPort = localService.getTargetServicePort() resulted in the entire WSDL being fetched and parsed and (probably) JAXB objects created for each invocation of test() method. However, load test of testGlobal() method resulted in only one full parse of WSDL, which occured when the class was loaded, as expected since the getTargetServicePort() is in the static block. Thus the testGlobal() looks efficient, what with reducing the Garbage collection (no need of collecting the service, port and other java objects which were derived from WSDL once the method is over since they are global) and network access time to download the WSDL and parse it.

These tests were performed on JBoss 5.1 server and the code was developed using NetBeans 6.8 (but development environment shouldn't matter I guess).

Assumption to be considered:
* No table locking or resource locking occurs from the webservice.
* The target WSDL doesn't change.
* The getTargetServicePort() has the code to get the QName, etc., i.e., the relevant WS client code.

Will a single Port object be able to handle all the requests properly without any deadlocks ? (From my testing, I give it a nod, but it may depend on the WebService code as well)
Is there any other better way to cache the WSDL or stop the server from accessing the WSDL always for generating the Java artifacts, provided that the target WSDL doesn't change ?
I am unable to get proper documents from where I could find out what the getWebServicePort() method is supposed to do.