zoukankan      html  css  js  c++  java
  • webService-cxf

    官网必备包,自己研究api:http://cxf.apache.org/download.html

    然后就是一个简单的例子了:

      先服务端:

        

    package com.cxf;
    
    import javax.jws.WebParam;
    import javax.jws.WebService;
    
    @WebService
    public interface IHelloWorld {
    
        public String sayHi(@WebParam(name="text")String text);
    }
    package com.cxf;
    
    import javax.jws.WebParam;
    import javax.jws.WebService;
    
    @WebService
    public class HelloWorld implements IHelloWorld {
    
        public String sayHi(@WebParam(name="text") String text){
            return "sayHi:"+text;
        }
    }
    package com.cxf;
    
    import javax.xml.ws.Endpoint;
    
    public class ServerSimple {
    
        public ServerSimple() throws Exception{
            System.out.println("starting Server");
            HelloWorld h=new HelloWorld();
            String address="http://localhost:9000/helloWorld";
            Endpoint.publish(address, h);
        }
        public static void main(String[] args) throws Exception{
            new ServerSimple();
            System.out.println("server ready...");
            Thread.sleep(60*1000);
            System.exit(0);
        }
    }

    然后客户端:

    package com.cxf;
    
    import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
    
    
    
    public final class Client {
    
        private Client(){}
        public static void main(String[] args) {
            JaxWsProxyFactoryBean factory=new JaxWsProxyFactoryBean();
            factory.setServiceClass(IHelloWorld.class);
            factory.setAddress("http://localhost:9000/helloWorld");
            IHelloWorld client=(IHelloWorld)factory.create();
            System.out.println("Invoke sayHi()....");
            System.out.println(client.sayHi(System.getProperty("user.name")));
            System.exit(0);
        }
    }

      至于关于什么是webservice什么的,请参考http://www.w3school.com.cn/ws.asp

      共同进步,共同学习

  • 相关阅读:
    rzc generate exited with code -2147450730.
    c#WebService动态调用
    c#BarTender打印,打印微调
    记一次ios下h5页面图片显示问题
    FID
    RSA密钥对生成,并解析公钥指数和模数
    angularjs-6
    angularjs-5
    angularjs-4
    angularjs-4
  • 原文地址:https://www.cnblogs.com/huzi007/p/3739082.html
Copyright © 2011-2022 走看看