CXF动态客户端调用webservice实例
2013-07-31 14:38
435 查看
使用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.
如果觉得这篇文章对你有帮助,请不要吝啬你的鼠标,帮助下博主,
进博主开的程序员茶店:http://csxstea.taobao.com
凑个人气。万分感谢。
注意 :不要指定
@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.
如果觉得这篇文章对你有帮助,请不要吝啬你的鼠标,帮助下博主,
进博主开的程序员茶店:http://csxstea.taobao.com
凑个人气。万分感谢。
相关文章推荐
- CXF动态客户端调用webservice实例
- CXF动态客户端调用webservice实例 遇到的问题
- CXF动态客户端调用webservice实例
- CXF动态客户端调用webservice实例
- CXF动态客户端调用webservice实例
- CXF soup webservice 动态客户端调用工具类
- CXF客户端开发--动态调用webservice
- CXF动态客户端调用JDK自带Webservice安全校验
- 使用CXF实现WebService,并在客户端实现动态调用
- CXF生成调用webservice的客户端
- CXF调用webservice 客户端 带soap header认证
- webservice CXF 客户端调用报错
- 利用axis1 客户端调用cxf写的webservice接口
- cxfspring boot整合cxf发布webservice服务和cxf客户端调用
- cxf动态调用webservice设置超时,测试线程安全
- 360doc-----简单CXF方式的webService客户端调用范例
- spring boot整合cxf发布webservice服务和spring boot整合cxf客户端调用webservice服务
- CXF生成webservice动态客户端
- axis 客户端调用CXF的webservice 解决参数传递不过去的问题
- cxf发布webservice及客户端调用