Apache cxf????????????????????????????????????WebService????????????

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Apache cxf????????????????????????????????????WebService????????????相关的知识,希望对你有一定的参考价值。

?????????static   apach   nts   ??????   ret   ?????????   div   png   ide   

????????????????????????????????????????????????????????????????????????????????????????????????????????????

restful???????????????????????????????????????????????????????????????????????????app?????????.net/C/C++??????????????????????????????????????????????????????????????????????????????????????????????????????

?????????????????????????????????????????????????????????apache???cxf??????????????????????????????????????????????????????

1??????????????????????????????cxf???cxf???apache???????????????????????????????????????http://www.apache.org/dyn/closer.lua/cxf/3.2.5/apache-cxf-3.2.5.zip

??????????????????????????????????????????

????????????????????????????????????????????????????????????????????????path?????????????????????????????????????????????

??????????????????

??????????????????????????????cxf,?????????3.2.5???

?????????????????????

????????????CXF_HOME??????????????????????????????CXF????????????????????????

??????????????????

?????????path???????????????bin

??????????????????

?????????cmd???????????????wsdl2java -help,??????????????????????????????????????????????????????????????????cxf

??????????????????

??????idea????????????????????????????????????

2???idea?????????cxf

????????????File--settings--????????????cxf--??????Tools?????????WebServices

??????????????????

?????????cxf???????????????

3???????????????????????????????????????????????????????????????????????????

package com.cxfdemo.hello;

import javax.jws.WebService;

@WebService
public interface MyWebService {
    int add(int a, int b);
    int minus(int a, int b);
}

?????????????????????????????????

 1 package com.cxfdemo.hello;
 2 
 3 import javax.jws.WebService;
 4 
 5 @WebService(endpointInterface = "com.cxfdemo.hello.MyWebService")
 6 public class MyWebServiceImpl implements  MyWebService{
 7     @Override public int add(int a, int b) {
 8         System.out.println(a+"+"+b+"="+(a+b)); return a+b;
 9     }
10     @Override public int minus(int a, int b) {
11         System.out.println(a + "-" + b + "=" + (a - b));
12         return a - b;
13     }
14 }

?????????????????????????????????Server?????? 

package com.cxfdemo.hello;


import javax.xml.ws.Endpoint;

public class MyServer {
    public static void main(String[] args) {
        String address = "http://localhost:8888/ms";
        Endpoint.publish(address,new MyWebServiceImpl());
    }
}

??????Client????????????

 1 package com.cxfdemo.hello;
 2 
 3 import javax.xml.namespace.QName;
 4 import javax.xml.ws.Service;
 5 import java.net.MalformedURLException;
 6 import java.net.URL;
 7 
 8 public class MyClient {
 9     public static void main(String args[]) {
10         try { URL url = new URL("http://localhost:8888/ms?wsdl");
11             //???????????? ??? ??????
12             QName qName = new QName("http://hello.cxfdemo.com/","MyWebServiceImplService");
13             Service service = Service.create(url, qName); MyWebService myWebservice = service.getPort(MyWebService.class);
14             System.out.println(myWebservice.add(2, 3)); System.out.println(myWebservice.minus(2, 3));
15         } catch (MalformedURLException e) {
16             e.printStackTrace();
17         }
18     }
19 }

???????????????????????????????????????????????????????????????MyServer,???????????????????????????????????????????????????????????????http://localhost:8888/ms?wsdl

?????????????????????????????????????????????

??????????????????

??????????????????????????????????????????????????????Client????????????

????????????????????????

??????????????????

 

 ???????????????????????????????????????WebService???????????????demo???

 

以上是关于Apache cxf????????????????????????????????????WebService????????????的主要内容,如果未能解决你的问题,请参考以下文章