purpose of using QName

11.2k views Asked by At

I am very much confused about the concept behind the QName.

lets take for example (I have taken these examples from http://www.mkyong.com/):

        ServerInfoService sis = new ServerInfoService();
        ServerInfo si = sis.getServerInfoPort();
        System.out.println(si.getServerName());

And with QName :

        URL url = new URL("http://localhost:8888/ws/image?wsdl");
        QName qname = new QName("http://ws.mkyong.com/", "ImageServerImplService");
        Service service = Service.create(url, qname);
        ImageServer imageServer = service.getPort(ImageServer.class);

Now my question is :

1) Is there any concepts based on which we have to decide which type of client we can write

2) What is the purpose or additional benefits in using QName because all I can see here is that it increases complexity as compared to simple client.

1

There are 1 answers

1
M.. On BEST ANSWER

Here is what i know:-

It depends on how you would want to make use of your client to invoke the web service. The first approach

ServerInfoService sis = new ServerInfoService(); ServerInfo si = sis.getServerInfoPort();

is the plain simple proxy generation approach; where-in you use a tool like wsimport to generate proxies/stubs to your SEI(Service Endpoint Interface)/web-service interfaces and invoke methods on it like any other java method call. Is mostly used in clients where you simply need to invoke methods on the web-service without getting into granular details.

The QName or rather the Service approach offer finer controls over how the client and webservice communicate. JAXWS 2.0 introduced something called as a Provider interface which was an alternative to your SEI which basically let a client communicate at the XML message level and provide a dynamic representation/view of your web-service to the client. More here. The primary use of Service API is mostly to create Dispatch instances which basically let a client dispatch to a speicific port(method qualified using QName api) using JAXB messages as XML payloads.

Other uses of Service api let a client call methods on the webservice asynchronously; provide access to handlers; etc. A good example of using the Service and QName approach to help you understand further and to relate to what i have said is this link here:- Dispatching Web Service Calls.

This being said there is a lot more to know and understand; but hope this gives you a start.