zoukankan      html  css  js  c++  java
  • java 发布webservice服务

    关键点:

    1:类上要注解@WebService

    2:方法上注解@WebMethod,方法参数:@WebParam来接

    3:发布配置:

    @Bean
        public ServletRegistrationBean dispatcherServlet() {
            ServletRegistrationBean sbean = new ServletRegistrationBean(new CXFServlet(), "/demo/WebServices/*");
            return sbean;
        }
    
        @Bean(name = Bus.DEFAULT_BUS_ID)
        public SpringBus springBus() {
            return new SpringBus();
        }
    
        @Bean
        public DemoService getService() {
            return new DemoService();
        }
    
        @Bean
        public Endpoint endpoint() {
            EndpointImpl point = new EndpointImpl(springBus(), getService());
            point.publish("demoWebService");
            return point;
        }
    

    4:启动项目,生成wsdl: http://127.0.0.1:8088/demo/WebServices/demoWebService?wsdl

    5:调用:

    JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
            Client client = dcf.createClient("http://127.0.0.1:8088/demo/WebServices/demoWebService?wsdl");
            Object[] objects = new Object[0];
            try {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("test001", "01");
    			// invoke("方法名",参数1,参数2,参数3....);
                objects = client.invoke("process", jsonObject.toString(), "123");
                System.out.println("objects[0]:" + objects[0]);
            } catch (Exception e) {
                e.printStackTrace();
            }
    

    6:原理

    webservice是一种通讯技术,wsdl 是一个xml文件,描述接口信息,使用soap来提供服务。 

    找到那个感觉 就算打开了那个脑洞

    本文来自博客园,作者:xiao~xiao,转载请注明原文链接:https://www.cnblogs.com/angin-iit/p/9561500.html

  • 相关阅读:
    iOS 添加微信分享
    IOS学习笔记——ViewController生命周期详解
    UI之CALayer详解(转)
    iOS CALayer讲解
    [leetcode] Minimum Path Sum
    [leetcode]Binary Tree Maximum Path Sum
    我是真的想去google啊
    C++ string 用法详解
    继续存博客
    bash中 2>&1 & 的解释
  • 原文地址:https://www.cnblogs.com/angin-iit/p/9561500.html
Copyright © 2011-2022 走看看