记录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解决跨域问题的方法. 服务端 编写服务代码,解 ...
随机推荐
- 高性能TcpServer(C#) - 1.网络通信协议
高性能TcpServer(C#) - 1.网络通信协议 高性能TcpServer(C#) - 2.创建高性能Socket服务器SocketAsyncEventArgs的实现(IOCP) 高性能TcpS ...
- Flutter 安装笔记
一. 安装镜像(有vpn的不用理) 1 打开终端 输入 open ~ ,回车 2 双击 .bash_profile 3 添加以下代码 后保存关闭即可(代码可能会变请直接到https://fl ...
- 关于项目中js原型的使用
在一个项目中为了减少全局变量的使用及模块化的开发我们使用的构造函数加原型的开发模式 var App = function(){ //管理构造函数的属性 this.name = 'jack' } //页 ...
- Android 项目主要文件
1.manifests下的AndroidManifest.xml是Andriod程序的清单文件,该文件是整个项目的配置文件,Android四大组件Activity.BroadcastReceiver. ...
- pdfium
https://github.com/SubtleCow/AccessControlListsintheDOM/tree/4673d995e5614bc682cecd22f9b2919b2360273 ...
- DNS分离解析
实验环境: 一台内网(client)1块网卡:一台网关(dns)2块网卡:一台外网1块网卡 DNS服务器开启路由转发 [root@localhost ~]# vi /etc/sysctl.conf n ...
- Sentinel 学习资料
Sentinel 学习资料 网址 官方github https://github.com/alibaba/Sentinel 官方中文文档 https://github.com/alibaba/Sent ...
- 多线程中fork与mutex
在多线程程序中fork出一个新进程,发现新的进程无法正常工作.因为:在使用fork时会将原来进程中的所有内存数据复制一份保存在子进程中.但是在拷贝的时候,但是线程是无法被拷贝的.如果在原来线程中加了锁 ...
- springboot整合OSS实现文件上传
OSS 阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量.安全.低成本.高可靠的云存储服务.OSS可用于图片.音视频.日志等海量文件的存储.各种终端 ...
- Artificial Intelligence in Finance
https://sigmoidal.io/real-applications-of-ai-in-finance/ Artificial Intelligence is taking the finan ...