cxf服务端创建与客户端调用和动态调用
来源:互联网 发布:国外域名购买十年 编辑:程序博客网 时间:2024/06/05 18:36
1。服务端的创建
首先我们写一个服务接口,这个接口有一个sayHi的操作。
jaxb是不支持maps的,处理List很方便,但是不直接支持maps,需要一个适配器。
IntegerUserMapAdapter的作用是完成Map<Integer,User>到IntegerUserMap的映射和IntegerUserMap到Map<Integer,User>的映射。方法分别是marshal和unmarshal
如果我们想保证参数在wsdl文件中是正确的可以使用下面的注解,否则参数就是arg0
下面写接口的实现
发布服务
然后就可以在http://localhost:9000/helloWorld?wsdl这个地址看到发布的服务了。
2.客户端的创建
第一种方式:
第二行和第三行代码可以不写
第二种方式:
动态调用
*/public class Test4 { private static final QName SERVICE_NAME = new QName("http://server.hw.demo/", "HelloWorld"); public static void main(String[] args) throws Exception { // 创建动态客户端 JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(); Client client = factory.createClient("http://localhost:9000/helloWorld?wsdl", SERVICE_NAME); ClientImpl clientImpl = (ClientImpl) client; Endpoint endpoint = clientImpl.getEndpoint(); List<ServiceInfo> serviceInfos=endpoint.getService().getServiceInfos(); ServiceInfo serviceInfo = endpoint.getService().getServiceInfos().get(0); QName bindingName = new QName("http://server.hw.demo/", "HelloWorldSoapBinding"); BindingInfo binding = serviceInfo.getBinding(bindingName); QName opName = new QName("http://server.hw.demo/", "sayHiToUser"); BindingOperationInfo boi = binding.getOperation(opName); BindingMessageInfo inputMessageInfo =null; if (!boi.isUnwrapped()) { //OrderProcess uses document literal wrapped style. inputMessageInfo = boi.getWrappedOperation().getInput(); } else { inputMessageInfo = boi.getUnwrappedOperation().getInput(); } List<MessagePartInfo> parts = inputMessageInfo.getMessageParts(); // only one part. MessagePartInfo partInfo = parts.get(0); Class<?> partClass = partInfo.getTypeClass(); System.out.println(partClass.getCanonicalName()); // GetAgentDetails Object inputObject = partClass.newInstance(); // 取得字段的set方法并赋值// PropertyDescriptor partPropertyDescriptor = new PropertyDescriptor("age", partClass);// Method userNoSetter = partPropertyDescriptor.getWriteMethod();// userNoSetter.invoke(inputObject,"20");// // 取得字段的set方法并赋值 PropertyDescriptor partPropertyDescriptor2 = new PropertyDescriptor("name", partClass); Method productCodeSetter = partPropertyDescriptor2.getWriteMethod(); productCodeSetter.invoke(inputObject,"lgx"); Object[] result = client.invoke(opName, inputObject); System.out.println(result[0]);
阅读全文
0 0
- cxf服务端创建与客户端调用和动态调用
- CXF客户端动态调用
- CXF客户端(动态调用)
- java cxf webservice 生成客户端 调用 服务端
- webservice-客户端调用cxf https服务端
- WEB项目 CXF与Spring整合服务端和客户端创建
- CXF生成webservice服务端,httpclient客户端调用webservice服务端
- CXF创建webservice客户端和服务端
- CXF创建webservice客户端和服务端
- CXF创建webservice客户端和服务端
- CXF创建webservice客户端和服务端
- 使用cxf生成客户端,并用生成的客户端调用服务端
- CXF动态客户端调用webservice实例
- CXF动态客户端调用webservice实例
- CXF客户端开发--动态调用webservice
- CXF动态客户端调用webservice实例
- CXF动态客户端调用webservice实例
- CXF动态客户端调用webservice实例
- App 初始化操作!
- git命令
- spring boot 发送kafka消息队列
- Tensorflow数据读取方法
- 简单排序算法时间空间复杂度分析及应用(6)-鸡尾酒排序(双冒泡排序)
- cxf服务端创建与客户端调用和动态调用
- 补码的意义
- RHEL4 安装yum
- Java中的enum详细解析------Java 语言中 Enum 类型的使用介绍
- 用CSS让字体在一行内显示不换行
- CLion使用CMake 导入本地Boost库学习笔记
- 【脚本语言系列】关于PythonWeb服务自动化REST,你需要知道的事
- 委托
- SVM