eclipse cxf wsdl2java,如何在Eclipse中使用CXF来使用WebService

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

2IWG6.jpg

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)

TMYC5.jpg

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.

解决方案

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

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值