I followed these steps to create a webservice:
- Created a service interface & implementation with @WebService and @WebMethod annotations
- Deployed the service
- Generated client stubs with wsimport
Invoked webservice with a client program that looks like:
public static void main(String[] args) throws Exception { URL url = new URL("http://SERVER:PORT/HelloWorldPOC/HelloWorldPOCImplService?wsdl"); QName qname = new QName("http://helloworld.poc.com/", "HelloWorldPOCImplService"); Service service = Service.create(url, qname); HelloWorldPOCImpl hello = service.getPort(HelloWorldPOCImpl.class); hello.execute("hello"); System.out.println("Done"); }
Questions:
- The WSDL location is provided in the client program. The WSDL location is hardcoded in the wsimport generated client stub as well. Why this redundancy?
I created the client stubs using wsimport using "localhost" path:
wsimport -keep http://localhost:9080/HelloWorldPOC/HelloWorldPOCImplService?wsdl
- I ran the client test program from the localhost with URL server part as "localhost". It worked. Then ran the same client from another system with server part as the hostname of the server. It worked.
- This means the WSDL location in the generated client stubs are not used?
- And we can generate the WSDL on localhost and deploy it anywhere without regenerating the client stubs? Only the caller client needs to retrieve the WSDL from the deployed server. Is this accepted practice or do we need to regenerate client for every deployed server?