cxf调用webservice
- 引入jar
<dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>3.1.11</version>
</dependency>
<dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http</artifactId><version>3.1.11</version>
</dependency>
<dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http-jetty</artifactId><version>3.1.11</version>
</dependency>
- web.xml--设置cxf
<!-- WebServices设置 --><servlet><servlet-name>CXFServices</servlet-name><servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class><load-on-startup>0</load-on-startup></servlet><servlet-mapping><servlet-name>CXFServices</servlet-name><url-pattern>/services/*</url-pattern></servlet-mapping>
- spring-mvc.xml---进行注册
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"xmlns:soap="http://cxf.apache.org/bindings/soap" xmlns:jaxws="http://cxf.apache.org/jaxws"xmlns:cxf="http://cxf.apache.org/core"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsdhttp://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsdhttp://cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"><!-- Import apache CXF bean definition --><import resource="classpath*:META-INF/cxf/cxf.xml" /><import resource="classpath*:META-INF/cxf/cxf-extension-soap.xml" /><import resource="classpath*:META-INF/cxf/cxf-servlet.xml" /><bean id="DistributeDataBean" class="com.webservice.FDistributeData.service.impl.DistributeDataServiceImpl" /><!-- CXF 配置WebServices的服务名及访问地址 --><jaxws:server id="DistributeDataServiceService" address="/DistributeDataServiceService" serviceClass="com.webservice.DistributeData.service.DistributeDataService"><!-- 要暴露的webservice服务 --><jaxws:serviceBean><ref bean="DistributeDataBean" /></jaxws:serviceBean></jaxws:server></beans>
- 书写实现类
@WebService(endpointInterface = "com.webservice.DistributeData.service.DistributeDataService")
public class DistributeDataServiceImpl {protected final Logger log = LoggerFactory.getLogger(getClass());}
- 进行验证
http://11.11.1.1:8061/dsg/rest/GetPatientInfo?wsdl
- 进行调用方式一
,借助jdk的wsimort.exe工具生成客户端代码,wsimort.exe工具位于Jdk的bin目录下,打开命令行窗口,切换到src目录,执行"wsimport -keep http://localhost:8080/WS_Server/Webservice?wsdl"生成客户端代码
执行wsdl2java -d D:\11//生成路径 -p com.web.GetPatientInfo//包名 -client D:\messageServer.xml//文件路径
安装包https://download.csdn.net/download/qq_36826635/12672717
- 调用--通过客户端
1.GetPatientInfo_Service getPatientInfo = new GetPatientInfo_Service();
2.GetPatientInfoPortType getPatientInfoSOAP11Port = getPatientInfo.getGetPatientInfoSOAP11Port();
3.xml = getPatientInfoSOAP11Port.getPatientInfo(userId, Password,patientIds);
- 通过代理
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://172.19.0.153:8080/scs-web/webservice/SignService?wsdl");
Object[] objects = new Object[0];
objects = client.invoke(opName, channel, templateId, isSeal, strJson, callBackUrl);
System.out.println("返回数据:" + objects[0]);
铜鼓http请求调用
package com.what21.service.demo02;import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;public class CallByHttp {private static String actionBySOAP(){StringBuilder sb = new StringBuilder();sb.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas" +".xmlsoap.org/soap/envelope/\" xmlns:sms=\"helloworld\">");sb.append("<soapenv:Header/>");sb.append("<soapenv:Body>");sb.append("<sms:sendSMS>");sb.append("<sms:in0>123</sms:in0>");sb.append("</sms:sendSMS>");sb.append("</soapenv:Body>");sb.append("</soapenv:Envelope>");return sb.toString();}private static String callWebService(String wsdl)throws Exception{System.setProperty("sun.net.client.defaultConnectTimeout","20000");System.setProperty("sun.net.client.defaultReadTimeout","20000");// URL连接URL url = new URL(wsdl);HttpURLConnection conn = (HttpURLConnection)url.openConnection();// conn.setRequestMethod("GET");conn.setRequestMethod("POST");conn.setRequestProperty("Content-Length", String.valueOf(actionBySOAP().getBytes().length));conn.setRequestProperty("Content-Type","text/xml; charset=GBK");conn.setDoOutput(true);conn.setDoInput(true); conn.setConnectTimeout(20000);// 请求输入内容OutputStream output = conn.getOutputStream();output.write(actionBySOAP().getBytes());output.flush();output.close();// 请求返回内容InputStreamReader isr = new InputStreamReader(conn.getInputStream());BufferedReader br = new BufferedReader(isr);StringBuilder sb = new StringBuilder();String str = null;while((str = br.readLine())!=null){sb.append(str + "\n");}br.close();isr.close();return sb.toString();}/*** @param args*/public static void main(String[] args) throws Exception {String WSDL = "http://127.0.0.1:8080/SMSService/webservices/SMSService";String result = callWebService(WSDL);System.out.println(result);}}
cxf调用webservice相关推荐
- 使用CXF调用webservice接口是超时异常的捕获处理
在调用第三方提供的webservice接口时我们可以设置超时时间: HTTPClientPolicy client = new HTTPClientPolicy(); client.setReceiv ...
- spring+cxf调用webservice接口
一.导入Spring和cxf的jar,在第一节中有说明. 二.编写Spring配置文件ClientBeans.xml ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
- java使用CXF调用webservice(生成客户端代码方式)
1:下载CXF 进入apache官网下载:http://cxf.apache.org/download.html 解压到某个路径下例如:C:\Program Files\apac ...
- CXF 调用 .net webservice
1.webservice 接口调用可参考jdk安装bin 下wsimport.exe. 2.本实例是CXF调用 .net webservice,且.net webservice接口参数是一个对象. 3 ...
- android 调用java webservice_android通过ksoap2调用java写的CXF 的webservice
如何添加ksoap2就不多说了,直接代码. 1.webservice:对应地址为http://192.168.1.119:8081/CXFTest/userService?wsdl 2.Activit ...
- Apache CXF实现WebService发布和调用
第一种方法:不用导入cxf jars 服务端: 1. 新建Web工程 2.新建接口和实现类.测试类 目录结构图如下: 接口代码: package com.cxf.spring.service;impo ...
- cxf调用接口的几种方式_Java调用CXF WebService接口的两种方式实例
1.静态调用 // 创建WebService客户端代理工厂 JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); // 判断是否抛出 ...
- spring boot整合cxf发布和调用webservice
一.前言 说起web service最近几年restful大行其道,大有取代传统soap web service的趋势,但是一些特有或相对老旧的系统依然使用了传统的soap web service,例 ...
- Spring集成CXF发布WebService并在客户端调用
Spring集成CXF发布WebService 1.导入jar包 因为官方下载的包里面有其他版本的sprring包,全导入会产生版本冲突,所以去掉spring的部分,然后在项目根目录下新建了一个CXF ...
- java使用cxf调用https方式的webservice
推荐尝试hutool工具调用: webservice服务利用hutool工具调用wsdl超简单_XYLANCC的博客-CSDN博客_hutool 调用wsdl 以下内容转载之后亲自测试过,又整理添加了 ...
最新文章
- OUYA游戏开发核心技术剖析OUYA游戏入门示例——StarterKit
- linux内存管理基本概念
- pytorch_导入d2l_pytorch包问题
- Deeplab训练时候unexpected label
- 面向关系数据库的智能索引调优方法
- 登录界面转换实现html,html5和css3登录注册表单界面切换动画
- hdfs java api读写
- CSS→代码语法、优先级、选择器、权值、字体文本、颜色、长度值、块状内联元素、盒模型、布局模型→层模型绝对相对定位、div排列、水平居中
- 这些话,是乔布斯给世间留下的真正伟大礼物
- 武汉理工大学计算机学院宿舍,武汉理工大学专业所属校区及新生住宿分布情况(v2.0)...
- CSR8系列ROM版本芯片介绍
- Ignite学习笔记——Ignite的安装与配置
- iOS开发之上传应用至APP store - 加急审核, 本人亲测苹果加速审核一年不止两次,只要理由充分,是可以多次的 。不过尽量避免
- 孙子兵法全文(原文)
- java Ofd 转图片_OFD文件怎么转换成图片格式
- java.io.IOException: Unable to read entire header; 275 bytes read; expected 512 bytes
- 计算机桌面文件为何不能剪贴,电脑不能复制粘贴是什么原因【方法介绍】
- php 正则 标点符号,js正则匹配中文标点符号
- OpenCV:图片文字分割
- 邝子平:vc兼做pe?