如何在Eclipse中使用CXF来使用WebService

如何在Eclipse中使用CXF来使用WebService

本文介绍了如何在Eclipse中使用CXF来使用WebService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用WEBSERVICE()使用Eclipse和Apache CXF。

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

我已经从,并已在Eclipse首选项> Web服务> CXF 2.x首选项

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

尝试创建新的Web Service Client在我的项目中,我不能选择Apache CXF作为WS运行时(OK按钮被禁用)

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)

我的项目不是一个动态的Web项目,是否与此有关?它是一个普通的Java项目,其JAR包含在其他动态Web项目中。

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.

推荐答案

确定按钮被禁用的原因是您尚未选择现有的服务器。由于它是一个普通的Java项目,您可能没有或需要配置服务器。

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.

您还可以创建Web服务客户端而不使用Eclipse向导,这可能更简单。

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

使用wsimport命令(在JDK中可用),可以从WSDL生成所需的Java源文件。

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

以下是访问Web服务的一个方法的示例。

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

这篇关于如何在Eclipse中使用CXF来使用WebService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 11:27