views:

35

answers:

1

How do you invoke a Java Web service constructor. Ideally when does constructor invocation happen while you consume the service from a client

+2  A: 

You do not explictly invoke a consructor from the client. From a WebServices perspective you are invoking an operation. You have no knowledge in the client of how that operation is implemented.

The the life-cycle of your server-side object is in the hands of your specific implemenation of JAX-WS. Possibly, at the time your server starts it will instantiate one or more copies of of your service object, and so that's when your constructor is called.

In Web Services each operation is usally a "stateless" action. If you have some standard processing you need to do then you would just include that processing in your implementation.

operationAaa(String exampleParam) {
    auditLog(exampleParam);

    doAaaWork(exampleParam);
}

operationBbb(String exampleParam) {
    auditLog(exampleParam);

    doBbbWork(exampleParam);
}

Now possibly you may have the kind of processing that could be implemented in a Handler. See this article

djna
Thanks for the Reply. So if i have a set of statements to be executed each time a web method is executed rather than executing once when the server starts, where should it be put. I assumed, putting this code in the constructor and creating a new Service at the client would invoke the constructor to get this job done;
I'll update the answer
djna