How to Consume a WebService using CXF in Eclipse

偶尔善良 提交于 2020-01-03 02:25:27

问题


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

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)

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.


回答1:


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();
}


来源:https://stackoverflow.com/questions/25391606/how-to-consume-a-webservice-using-cxf-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!