记录webservice
公司的一个老项目,定义了接口,供其他应用访问.定义的方式就是webservice.
我这边的环境是springboot.
首先引入依赖jar
声明一个服务端. @WebSerevice注解中name则是对外暴露的服务.
被@WebMethod 注解的方法,则是webservice对外暴露的方法.
import com.alibaba.fastjson.JSON;
import com.prologint.waybill.api.ParameterEntity.GetWaybillYTRequest;
import com.prologint.waybill.api.ParameterEntity.GetWaybillYTResponse;
import com.prologint.waybill.service.GetWaybillYTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.jws.WebMethod;
import javax.jws.WebService; @WebService(name = "WaybillYT")
@Component
public class WaybillYTService { @WebMethod
public String getWaybillYT(String billNo, String branchId, String consignor) {
return "ok";
}
}
配置webservice.
import javax.xml.ws.Endpoint; import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration
public class WaybillYTServiceConfig {
@Autowired
private Bus bus; @Autowired
private WaybillYTService waybillYTService; /** JAX-WS **/
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, waybillYTService);
endpoint.publish("/WaybillYT");
return endpoint;
}
}
客户端测试,端口替换为自己的服务器port即可
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; public class Cilent {
public static void main(String[] args) {
// 创建动态客户端
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:80/services/WaybillYT?wsdl");
Object[] objects = new Object[0];
try {
// invoke("方法名",参数1,参数2,参数3....);
objects = client.invoke("getWaybillYT", "111111","222222222","3333333333");
System.out.println("返回数据:" + objects[0]);
} catch (java.lang.Exception e) {
e.printStackTrace();
}
}
}
记录webservice的更多相关文章
- JAVA记录-WebService开发部署
JWS.Axis2.cxf 1.下载axis2.war和axis2.bin.zip 2.将axis2.war包部署到Tomcat下,启动Tomcat测试:http://localhost:8089/a ...
- WebService1
一.什么是WebService(来源百度百科) Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述. ...
- spring+cxf 开发webService(主要是记录遇到spring bean注入不进来的解决方法)
这里不介绍原理,只是记录自己spring+cxf的开发过程和遇到的问题 场景:第三方公司需要调用我们的业务系统,以xml报文的形式传递数据,之后我们解析报文存储到我们数据库生成业务单据: WebSer ...
- SSH与Webservice整合记录
一.首先搭好SSH框架: 1. Struts:MyEclipse菜单栏MyEclipse——>Project Capabilities——>Add Struts Capabilities, ...
- 客户端(C#)调用CXF搭建的webservice的出现一些问题记录
最近把XFire框架搭建的一个webservice换成CXF框架.访问webservice的客户端是C#写的.客户端调用webservice,数据能在客户端得到.看起来显然是成功了. 但其中在VS中添 ...
- Jquery调用webService的四种方法 转载-记录
我总结几个关键点 1. 服务必须声明为ScriptService(否则会出现下面的问题) 2.服务的方法不需要任何更改,保持原状 3.客户端用jquery的.ajax方法来调用 3.1 type必须是 ...
- WSDL测试webservice接口记录
收到一个事情,需要对接第三方API,对方给了个service,看了一下,原来是webservices的. 上一次测试webervice的接口,还是至少八九年前的时候了,这种相对比较老旧的也好久不在使用 ...
- WebService 学习记录
-------------------------------------------PS:这个WebService 服务必须一直开着,关闭就没法访问了 Web Service 教程 一.webser ...
- webserive学习记录6-页面请求webservice
前面都是通过JAVA代码访问webservice服务,下面将介绍通过javascript,jquery访问webservice服务并介绍过过servlet解决跨域问题的方法. 服务端 编写服务代码,解 ...
随机推荐
- 4-consul HTTP API及实践
其他参考:https://www.cnblogs.com/duanxz/p/9660766.html 原文:https://www.douban.com/note/629645759/ 注意:使用AP ...
- HighChat动态绑定数据 数据后台绑定(四)
后台绑定数据,直接返回json数据 IList<SummaryHour> adHourData = summarybll.FindList(str); List<, , , , , ...
- SAP S4HANA BP事务代码初始界面的ROLE和Grouping配置
SAP S4HANA BP事务代码初始界面的ROLE和Grouping配置 SAP S/4 HANA系统里,创建供应商不再使用MK01/FK01/XK01等事务代码,而是使用BP事务代码. BP事务代 ...
- <转>WPF 中的绑定
在WPF应用的开发过程中Binding是一个非常重要的部分. 在实际开发过程中Binding的不同种写法达到的效果相同但事实是存在很大区别的. 这里将实际中碰到过的问题做下汇总记录和理解. 1. so ...
- Android培训准备资料之Android开发环境的搭建
Android开发环境的搭建主要分为以下四步: (1)下载JDK并安装 (2)配置JDK环境变量 (3)下载安装Android Studio (4)配置Android SDK环境变量(可执行可不执行) ...
- vue学习指南:第二篇(详细Vue基础) - Vue的指令
一. Vue 的介绍 1. vue是一个 mvvm 的框架.(面试官经常会问的),angular 是 mvc的框架. 2. vm 是 vum 的实例,这个实例存在计算机内存中,主要干两件大事: 1. ...
- NoSuchMethodError 常见原因及解决方法
相 关 阅 读 导读 『StabilityGuide』是阿里多位阿里技术工程师共同发起的稳定性领域的知识库开源项目,涵盖性能压测.故障演练.JVM.应用容器.服务框架.流量调度.监控.诊断等多个技术领 ...
- [转]技术比较Agent和Agentless监控优缺点
本文并非原创,转自:http://wenku.baidu.com/link?url=NGT2NA7Lf6fZSPmcOxFQqL4cYROHlIOJyiWCnGdwv3kljMqub-6zyjgsSw ...
- Centos7 安装使用virtualenvwrapper
退出所有的虚拟环境,在物理环境下安装 1.下载安装virtualenvwrapper pip3 install virtualenvwrapper 2.查看python3的文件和virtualenvw ...
- Rust中的函数调用
注意区别语句和表达式哟. Rust是一门基于表示式的语言,牢记!!! fn main() { println!("Hello world!"); another_function( ...