公司的一个老项目,定义了接口,供其他应用访问.定义的方式就是webservice.

我这边的环境是springboot.

首先引入依赖jar

    

声明一个服务端. @WebSerevice注解中name则是对外暴露的服务.

被@WebMethod 注解的方法,则是webservice对外暴露的方法.

  1. import com.alibaba.fastjson.JSON;
  2. import com.prologint.waybill.api.ParameterEntity.GetWaybillYTRequest;
  3. import com.prologint.waybill.api.ParameterEntity.GetWaybillYTResponse;
  4. import com.prologint.waybill.service.GetWaybillYTService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Component;
  7. import javax.jws.WebMethod;
  8. import javax.jws.WebService;
  9.  
  10. @WebService(name = "WaybillYT")
  11. @Component
  12. public class WaybillYTService {
  13.  
  14.   @WebMethod
  15. public String getWaybillYT(String billNo, String branchId, String consignor) {
  16. return "ok";
  17. }
  18. }

配置webservice.

  1. import javax.xml.ws.Endpoint;
  2.  
  3. import org.apache.cxf.Bus;
  4. import org.apache.cxf.jaxws.EndpointImpl;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.Configuration;
  8.  
  9. @Configuration
  10. public class WaybillYTServiceConfig {
  11. @Autowired
  12. private Bus bus;
  13.  
  14. @Autowired
  15. private WaybillYTService waybillYTService;
  16.  
  17. /** JAX-WS **/
  18. @Bean
  19. public Endpoint endpoint() {
  20. EndpointImpl endpoint = new EndpointImpl(bus, waybillYTService);
  21. endpoint.publish("/WaybillYT");
  22. return endpoint;
  23. }
  24. }

客户端测试,端口替换为自己的服务器port即可

  1. import org.apache.cxf.endpoint.Client;
  2. import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
  3.  
  4. public class Cilent {
  5. public static void main(String[] args) {
  6. // 创建动态客户端
  7. JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
  8. Client client = dcf.createClient("http://localhost:80/services/WaybillYT?wsdl");
  9. Object[] objects = new Object[0];
  10. try {
  11. // invoke("方法名",参数1,参数2,参数3....);
  12. objects = client.invoke("getWaybillYT", "111111","222222222","3333333333");
  13. System.out.println("返回数据:" + objects[0]);
  14. } catch (java.lang.Exception e) {
  15. e.printStackTrace();
  16. }
  17. }
  18. }

记录webservice的更多相关文章

  1. JAVA记录-WebService开发部署

    JWS.Axis2.cxf 1.下载axis2.war和axis2.bin.zip 2.将axis2.war包部署到Tomcat下,启动Tomcat测试:http://localhost:8089/a ...

  2. WebService1

    一.什么是WebService(来源百度百科) Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述. ...

  3. spring+cxf 开发webService(主要是记录遇到spring bean注入不进来的解决方法)

    这里不介绍原理,只是记录自己spring+cxf的开发过程和遇到的问题 场景:第三方公司需要调用我们的业务系统,以xml报文的形式传递数据,之后我们解析报文存储到我们数据库生成业务单据: WebSer ...

  4. SSH与Webservice整合记录

    一.首先搭好SSH框架: 1. Struts:MyEclipse菜单栏MyEclipse——>Project Capabilities——>Add Struts Capabilities, ...

  5. 客户端(C#)调用CXF搭建的webservice的出现一些问题记录

    最近把XFire框架搭建的一个webservice换成CXF框架.访问webservice的客户端是C#写的.客户端调用webservice,数据能在客户端得到.看起来显然是成功了. 但其中在VS中添 ...

  6. Jquery调用webService的四种方法 转载-记录

    我总结几个关键点 1. 服务必须声明为ScriptService(否则会出现下面的问题) 2.服务的方法不需要任何更改,保持原状 3.客户端用jquery的.ajax方法来调用 3.1 type必须是 ...

  7. WSDL测试webservice接口记录

    收到一个事情,需要对接第三方API,对方给了个service,看了一下,原来是webservices的. 上一次测试webervice的接口,还是至少八九年前的时候了,这种相对比较老旧的也好久不在使用 ...

  8. WebService 学习记录

    -------------------------------------------PS:这个WebService 服务必须一直开着,关闭就没法访问了 Web Service 教程 一.webser ...

  9. webserive学习记录6-页面请求webservice

    前面都是通过JAVA代码访问webservice服务,下面将介绍通过javascript,jquery访问webservice服务并介绍过过servlet解决跨域问题的方法. 服务端 编写服务代码,解 ...

随机推荐

  1. 高性能TcpServer(C#) - 1.网络通信协议

    高性能TcpServer(C#) - 1.网络通信协议 高性能TcpServer(C#) - 2.创建高性能Socket服务器SocketAsyncEventArgs的实现(IOCP) 高性能TcpS ...

  2. Flutter 安装笔记

    一. 安装镜像(有vpn的不用理) 1  打开终端 输入 open ~  ,回车 2  双击 .bash_profile  3  添加以下代码 后保存关闭即可(代码可能会变请直接到https://fl ...

  3. 关于项目中js原型的使用

    在一个项目中为了减少全局变量的使用及模块化的开发我们使用的构造函数加原型的开发模式 var App = function(){ //管理构造函数的属性 this.name = 'jack' } //页 ...

  4. Android 项目主要文件

    1.manifests下的AndroidManifest.xml是Andriod程序的清单文件,该文件是整个项目的配置文件,Android四大组件Activity.BroadcastReceiver. ...

  5. pdfium

    https://github.com/SubtleCow/AccessControlListsintheDOM/tree/4673d995e5614bc682cecd22f9b2919b2360273 ...

  6. DNS分离解析

    实验环境: 一台内网(client)1块网卡:一台网关(dns)2块网卡:一台外网1块网卡 DNS服务器开启路由转发 [root@localhost ~]# vi /etc/sysctl.conf n ...

  7. Sentinel 学习资料

    Sentinel 学习资料 网址 官方github https://github.com/alibaba/Sentinel 官方中文文档 https://github.com/alibaba/Sent ...

  8. 多线程中fork与mutex

    在多线程程序中fork出一个新进程,发现新的进程无法正常工作.因为:在使用fork时会将原来进程中的所有内存数据复制一份保存在子进程中.但是在拷贝的时候,但是线程是无法被拷贝的.如果在原来线程中加了锁 ...

  9. springboot整合OSS实现文件上传

    OSS 阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量.安全.低成本.高可靠的云存储服务.OSS可用于图片.音视频.日志等海量文件的存储.各种终端 ...

  10. Artificial Intelligence in Finance

    https://sigmoidal.io/real-applications-of-ai-in-finance/ Artificial Intelligence is taking the finan ...