Search code examples
javaweb-servicescxf

simple web service: putting endpointname, servicename, etc. together


I'm trying Apache's simplest "Hello World" webservice (http://cxf.apache.org/docs/a-simple-jax-ws-service.html); I have purposely altered it a little to learn more about how to do things instead of just copying all their code.

My service implementation specifies the interface it implements in the package "hw":

@WebService(endpointInterface = "hw.HelloWorld", serviceName = "HelloWorld")

The program that "publishes" the web service (which I gather means operates as the server for it) has the implementation in its own (quite correct) package:

HelloWorldImpl implementor = new hwimpl.HelloworldImpl();
Endpoint.publish("http://localhost:9000/helloworld", implementor);

and then sleeps for 5 minutes, during which time the URL the instructions say to put in the browser displays the WSDL. That much works.

http://localhost:9000/helloWorld?wsdl

My client has:

private static final QName SERVICE_NAME 
    = new QName("http://server.hw.demo/", "HelloWorld");
private static final QName PORT_NAME 
    = new QName("http://server.hw.demo/", "HelloWorldPort");

// the following in a method, of course
String endpointAddress = "http://localhost:9000/helloWorld";
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
HelloWorld hw = service.getPort(HelloWorld.class);
System.out.println(hw.sayHi("Albert"));

I don't know how SERVICE_NAME and PORT_NAME relate to my service. The "server.hw.demo" strings came from the example, and do not correspond to packages in my code, or "reversed" packages as seemed to be used for namespaces; should they? What do they correspond to? I have nothing in my code, except here, that uses "server.hw.demo"; what is that string supposed to be?

Does it matter that my implementation and my interface are in different classes?

My client does not work, and I posted that as a question, but it's long and no one has responded to it. I am making a stab at understanding this part; it seems to me the most likely culprit. I'd delete the other question if I knew how.


Solution

  • Target namespace
    (source: javatips.net)

    Above screenshot you can see that Target namespace http://student.com , this is because we are created package as com.student. Target namespace must be on reverse order of a java package, also need to append http:// before the package

    Reference my blog:

    http://javatips.net/blog/2012/04/expose-cxf-service-with-rest-and-soap