Web Services 详解

                                    解决异构系统的通讯和整合

                                                                            Axis,Xfire,CXF

    首先我来介绍一下Web Services的相关概念:

        1.WSDL (Web services 描述语言)

        2.UDDI (通用描述、发现及整合)

        3.SOAP (简易对象访问协议)

 

    先看一下工作流程图:

Web Services 详解

 

SOAP的协议基础如图所示:

Web Services 详解

 

 接下来介绍一下安装步骤:

        将axis-bin-1_4.zip文件解压,将webapps/axis考贝到tomcat中的TOMCAT-HOME/webapps下
            在TOMCAT-HOME/webapps/axis下创建MyMath.jws文件,内容如下: 
                   

          public class MyMath {
                         public int squared(int x) {
                          int result = x * x;
                          System.out.println("the squared of " + x + " is " + result);
                          return result;
                             }
                    }

        启动Tomcat,访问如下 http://localhost:8080/axis/MyMath.jws ,如果可以正常访问Web Service部署成功

接下来在Eclipse中建立java项目,引入Axis中的所有的包,建立MyMathClient.java文件,编写调用web service的客户端代码:
public class MyMathClient {
    
   private static final String endPoint = "http://localhost:8080/axis/MyMath.jws?wsdl";
    
    public static void main(String args[]){
        Service service = new Service();
        try {
            Call call = (Call)service.createCall();
            call.setTargetEndpointAddress(new URL(endPoint));
            Integer result =(Integer)call.invoke("squared", new Object[]{10}); 
            System.out.println(result);
} catch (ServiceException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }catch(RemoteException e){
            e.printStackTrace();
        }
    }
}

这样就可以调用配置好的WebServices了。

你可能感兴趣的:(eclipse,webservice,SOAP,axis,UDDI)