user1084509
user1084509

Reputation: 1902

How to Consume a WebService using CXF in Eclipse

I am trying to consume a WEBSERVICE (http://www.detecno.mx/WCFTimbrador/DetecnoPac.svc?wsdl) using Eclipse and Apache CXF.

I already downloaded the latest Apache CXF version (2.5.2) from http://cxf.apache.org/ and already configured its location in Eclipse Preferences > Web Services > CXF 2.x Preferences

enter image description here

When trying to create the new Web Service Client in my project, I can't select Apache CXF as the WS runtime (OK button is disabled) enter image description here

My project is not a dynamic web project, does it have to do with this? It is a normal Java Project, whose JAR is included in other Dynamic Web Projects.

Upvotes: 1

Views: 6355

Answers (1)

asohun
asohun

Reputation: 331

The reason that the OK button is disabled is that you have not selected an existing server. Since it is a normal Java Project, you probably don't have or need to configure a server.

You can also create the web service client without using the Eclipse wizard, which may be simpler.

Using the wsimport command (available in the JDK), you can generate the required Java source files from the WSDL.

wsimport -s E:\workspace\cxf\src http://www.detecno.mx/WCFTimbrador/DetecnoPac.svc?wsdl

Below is an example of a method accessing the web service.

public static void main(String[] args) {
    ServiceDetecnoPAC serviceDetecnoPAC = new ServiceDetecnoPAC();
    IDetecnoPac port = serviceDetecnoPAC.getPort(IDetecnoPac.class);

    ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.detecno.mx/WCFTimbrador/DetecnoPac.svc?wsdl");

    Client client = ClientProxy.getClient(port);
    org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();

    port.obtenerHoraServidor();
}

Upvotes: 1

Related Questions