CXF动态客户端调用webservice实例

使用CXF实现WebService,并在客户端实现动态调用编写服务器注意事项


注意 :不要指定
@SOAPBinding(style=Style.RPC, use=Use.LITERAL) 因为cxf 不支持:rpc、encoded,在动态客户调用过程。

cxf webservice开发资料,网上一搜大部分是类同的,跟官方的例子一样。
都是简单的静态调用例子。对动态调用的资料以及错误很少。本人被折腾了不行的情况下,
在一哥们的博客  http://hi.baidu.com/flierssp/item/2de0745c1afc1f3b32e0a96f 中看到动态调用不支持RPC才恍然大悟。
服务器端:
package com.rodjson.cxf;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
/*@SOAPBinding(style=Style.RPC, use=Use.LITERAL) 注意 :如果要动态调用一定要注释掉这句代码*/
public interface HelloWorld {
 @WebMethod
 String sayHi(@WebParam(name="text") String text);
 }
package com.rodjson.cxf;
---HelloWorldImpl---
import javax.jws.WebService;

@WebService(endpointInterface="com.rodjson.cxf.HelloWorld",
   
  serviceName="HelloWorld" )
public class HelloWorldImpl implements HelloWorld {
    
           public String sayHi(String text) {
            System.out.println("sayHi called");     
            return "Hello " + text;
          }
          
}

部署:
package com.rodjson.cxf;

import javax.xml.ws.Endpoint;

public class webServiceApp {
 public static void main(String[] args) {
  System.out.println("web service start");
  HelloWorld implementor = new HelloWorldImpl();
  String address = "http://localhost:8080/helloWorld";
  Endpoint.publish(address, implementor);
  System.out.println("web service end");
 }

}
至于部署的方法网上很多,我就不提了,重点是动态客户端调用以及错误的识别

package com.rodjson.cxf;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

public class ClientObj {
public static void main(String[] args) {
 JaxWsDynamicClientFactory  factory =JaxWsDynamicClientFactory.newInstance();
    Client client =factory.createClient("http://localhost:8080/cxf/services/HelloWorld?wsdl");
    try {
     Object[] obj =client.invoke("sayHi","xiao");
  System.out.println("resp:"+obj[0]);
 } catch (Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
}
}

错误如下:
2012-5-23 20:53:34 org.apache.cxf.common.jaxb.JAXBUtils logGeneratedClassNames

信息: Created classes: 

javacTask: 无源文件

用法: javacTask <options> <source files>

-help 用于列出可能的选项

2012-5-23 20:53:34 org.apache.cxf.endpoint.dynamic.DynamicClientFactory createClient

严重: Could not compile java files for http://127.0.0.1:9082/CrmWeb/services/CrmInterServer?wsdl.


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值