webservice

http://www.ibm.com/developerworks/cn/java/j-jws6/

客户端:http://www.blogjava.net/fatbear/archive/2009/03/16/260032.html

CXF 2.0 学习笔记-2(客户端)



try {
            JaxWsProxyFactoryBean  factory = new JaxWsProxyFactoryBean (); 
            factory.setServiceClass(WebServiceSample.class);
            factory.setAddress("http://127.0.0.1:9080/cxfTest/ws/HelloWorld");
            Object obj = factory.create();
            System.out.println(obj == null ? "NULL":obj.getClass().getName());
            if(obj != null){
                WebServiceSample ws = (WebServiceSample)obj;
                String str = ws.say("test");
                System.out.println(str);
                
                str = ws.say("1111");
                System.out.println(str);
                
                User u = new User();
                JAXBElement <String> je = 
                    new JAXBElement <String>(
                            new QName("http://bean.cxf.hs","name"),
                            String.class,"张三"); 
                u.setName(je);
                str = ws.sayUserName(u);
                System.out.println(str);
                
                //通过对象来交互
                ReqBean req = new ReqBean();
                req.setExp(new JAXBElement <String>(
                            new QName("http://bean.cxf.hs","exp"),
                            String.class,"<exp>111<exp>"));
                req.setSeqId(new JAXBElement <String>(
                        new QName("http://bean.cxf.hs","seqId"),
                        String.class,"12345678"));
                RespBean resp = ws.action(req);
                System.out.println("resp_id:"+resp.getRespId().getValue());
                System.out.println("resp_exp:"+resp.getExp().getValue());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

你可能感兴趣的:(webservice)