Axis 思考总结

Web Service


    Web Service是建立可互操作的分布式应用程序的新平台。Web Service平台是一套标准,它定义了应用程序如何在Web上实现互操作性。
    函数或方法调用通常发生在不同计算机间的不同语言编写的应用系统中,通过网络通讯实现函数和方法调用的能力。

    "A Web Service  is a software application identified by a URL, whose interfaces and bindings are capable of being defined, described, and discovered as XML artifacts. A Web service supports direct interactions with other software agents using XML-based messages exchanged via Internet-based protocols."

    Web Services provide a distributed computing approach for integrating heterogeneous applications over the Internet and have received wide acceptance as an important implementation of SOA.

    Its specifications are completely independent of programming language, operating system, and hardware to promote loose coupling.

Based on open technologies:
    eXtensible Markup Language (XML)
    SOAP: An XML-based RPC and messaging protocol for accessing a Web service.
    UDDI: A registry mechanism that can be used to look up Web service descriptions.
    WSDL: An industry standard for describing a Web Service.

    BPEL4WS: Define business processes as coordinated sets of Web service interactions, enable the creation of compositions of Web services.

    Basic Web Services combine the power of two ubiquitous technologies: XML, the universal data description languate; and the HTTP, transport protocol widely supported by browser and Web servers.

-------------------------------------------------昏割线-------------------------------------------------------

Axis

  Apache Axis 是Apache Web Service 项目中的子项目,其最初起源于IBM的"SOAP4J",应该属于最早的一批用于构造基于SOAP应用的Framework。目前,Apache Axis 的核心是一个SOAP处理器,用于开发包括客户端,服务器端,SOAP Gateway等各种应用。事实上Apache Axis在了1.0版后,其发行版本还包括了完整的J2EE服务器插件,WSDL支持和生成,TCP/IP监视器等组件,从这个意义上来说Apache Axis已不仅仅是一个SOAP框架了,它包含了除去UDDI外整个Web Service协议栈(Protocol Stack)的支持。

  Axis2是下一代Apache Axis。Axis2虽然由Axis 1.x处理程序模型提供支持,但它具有更强的灵活性,并可拓展到新的体系结构。Axis2基于新的体系结构进行了全新编写,而且没有采用Axis 1.x的常用代码。支持开发Axis2的动力是探寻模块化更强、灵活性更高和更有效的体系结构,这种体系结构可以很容易地插入到其他相关Web服务标准和协议(如 WS-Security、WS-Reliable Messaging等) 的实现中。

Apache Axis()

  Apache Axis (Apache eXtensible Interaction System) is an open source, XML based Web service framework. It consists of a Java and a C++ implementation of the SOAP server, and various utilities and APIs for generating and deploying Web service applications. Using Apache Axis, developers can create interoperable, distributed computing applications. Axis is developed under the auspices of the Apache Software Foundation.
  Axis for java
  When using the java version of Axis there are two ways to expose Java code as Web service. The easiest one is to use Axis native JWS (Java Web Service) files. Another way is to use custom deployment. Custom deployment you to customize resources that should be exposed as Web service.


-------------------------------------------------昏割线-----------------------------------------------------------
~\(≧▽≦)/~实践部分~\(≧▽≦)/~
有待研究点,
(1)Axis的服务器
(2)WSDL 【接触过些】
(3)REST服务【接触过些】 这些是比较值得分析的技术点
-------------------------------------------------昏割线-----------------------------------------------------------

作为个人总结Web Service的应用过程,自己对过去自己实现的一个简单订餐的实例进行分析说明:
【~\(^o^)/~水平有限,望共同提高~\(^o^)/~】
总体过程图示如下:

由上图,前台就是有界面的客户端,Web Service发布就是服务器端。【由于只是对Web Service进行总结,因此,对逻辑的实现不做任何说明,仅仅将重点放在对Web Service的发布和调用过程】

(1) Server 端【Java 开发】

     服务器端是java开发的Web Service,放置于tomcat中的Axis2引擎下发布的。

    ❤ 发布过程如下:

   I. 用在myeclipse下集成的东西进行发布Web Service服务【若没有自行Google查找或bing寻找安装】

  

   II. 启动Axis2 Service Archiver,将OMS工程下的bin文件添加,如下图所示:


  III. 点击Next


   IV. 点击Next【看清楚,下面是我们数据库需要的驱动,若没有,必定失败,原理清楚了(⊙_⊙)?!】


   V.点击Next

  

  VI.点击Next

 

   其中,Service name是自己起的Web Service发布名字,Classname 是自己的发布类名。

   VII. 点击Next


Output file location 是输出的OrderMealSystem.aar输出位置。

Output File Name 是输出文件的名字,这里用OrderMealSystem

ü  问题说明

通过上面的过程,就可以实现java project的类,也即函数的发布工作,为客户端提供了功能支持。

主要是注意lib库文件的添加,如mysql访问lib文件,否则,就调用函数能成功,但难以执行对数据库的操作。


    ❤❤Tomcat启动与运行Web Service 

     能启动tomcat的前提,需要安装java的jdk,这里就进行省略此过程说明。因为这是java开发最基本的部分。安装jdk,并达到让系统能够默认(即:系统path路径)找到,java和javac即可。这是安装jdk的目的和思想。

    I. Tomcat 启动




ü  问题说明

(1).这里重点关注一下,tomcat服务器的版本,主要是涉及到系统是多少位系统,如果是32bit 就用x86;否则选择64bit,当然JDK也要与之相配。

(2).这里需要在java的JDK安装成功的前提下,否则,tomcat是不可能启动起来的,会报错误,所以在这里需要对JDK正确安装,如系统变量添加的选项正确等等。

(3).这个过程可以了解到,系统变量的概念。以及tomcat的服务器作用。

    ❤❤❤Axis2引擎的添加,并添入OMS服务包【OrderMealSystem.aar】







    ❤❤❤代码分析如下:


第一、各个层次的隔离,使得层次清晰,也为第二的单元测试打下基础
这个层次封装是基于MVC框架的思想,这个思想就是将功能分切成模块,一点点蚕食,使得工程有很强的鲁棒性,结构清晰的同时,也对测试有很好的优越性。
第二、 JUnitTest测试
【自己会抽时间着重分析一下>_<】
单元测试提高了开发的效率的同时,也使得内容很有效的建立和实现,保证了调用过程和结果的准确性。


(2) Client 端【C#开发】

    客户端是C#开发的Web Service Client,用于向服务器发出WebService请求的。


   通过C#的Web Service自动生成工具,生成客户端访问程序,从而建立Web Service客户端,用于和JavaWeb Service进行交互。


(1)右击项目,进行“添加服务引用”,选择“高级”,再选择“添加Web 引用”,如下图所示:


(2)输入URL地址,并点击 箭头,修改“Web 引用名”为OMSClient结果如下图:


(3)点击添加引用就可创建成功。形成的目录树,如下所示:

上目录树中,对界面程序的说明如下:

  Form1.cs是主界面:【木美工哒天分=。=】


Process.cs是进度条设计界面:


tipsForm2.cs是访问过程提示界面:


存在问题点说明:

1.C#自动生成过程的错误

************** 异常文本 **************
System.InvalidOperationException: 在 ServiceModel 客户端配置部分中,找不到名称“OMSAxisSoap11Binding”和协定“ServiceReference1.OMSAxisPortType”的终结点元素。这可能是因为未找到应用程序的配置文件,或者是因为客户端元素中找不到与此名称匹配的终结点元素。
   在 System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   在 System.ServiceModel.ChannelFactory.ApplyConfiguration(String …
此问题的解决是因为生成的app.config中配置的文件出现内容重复现象,尤其是<endpoint>中,这种现象的存在是自动生成的顺序步骤出了问题,只需要对其进行修改,按照上述说明的生成过程,是没有问题的。


针对代码进行说明【对界面不做任何说明咯~】
(1)C#对自动生成的app.config进行展示,由于很简单,就不做说明了。


   
   

   
   
    
    
    
        
     
     
            
      
      
http://localhost:8080/axis2/services/OMSWebService.OMSWebServiceHttpSoap11Endpoint/



批注:其中,我们只要关注applicationSettings就可以知道自己如何修改和书写配置文件了。【很容易对不~O(∩_∩)O~】
(2)发送Web Service消息方式
注意到,我们上面的Web References中的注册名字叫做OMSClient,因此,直接进行以嘞的方式使用,代码如下:

//C#访问Web Service的调用方法大部分都是自动生成,但是需要对其进入深入理解,才能够很容易上手。^_^

/*订餐API*/
OMSMessage omsMessage = new OMSMessage();//OMSMessage是自定义类,包含了Web Service所需要的参数
//对omsMessage 消息参数【OMSTelephone,OMSDate,OMSName】进行填充

//发送 Web Service 消息
OMSClient.OMSWebService WBClient = new OMSClient.OMSWebService();
//orderMealStr 是Web Service 返回的数据消息
String orderMealStr = WBClient.OrderMeal(omsMessage.OMSTelephone, omsMessage.OMSDate, omsMessage.OMSName);


/*删除电话API*/
OMSMessage omsMessage = new OMSMessage();//OMSMessage是自定义类,包含了Web Service所需要的参数

//对omsMessage 消息参数【OMSTelephone】进行填充

OMSClient.OMSWebService WSClient = new OMSClient.OMSWebService();
//resultWB 是Web Service 返回的数据消息
String resultWB = WSClient.DeleteMeal(omsMessage.OMSTelephone);

一个配置,可以浏览Web Service,如下:



源码地址:【需要一个丸子>_<】

http://download.csdn.net/detail/ying66feng/8164625

补充一点,Java客户端如何调取Web Service:

代码如下:

调用方法【BookMealSystemWB.java

package Book.BookMealSystem;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class BookMealSystemWB {
	  private RPCServiceClient serviceClient;
	  private Options options;
	  private EndpointReference targetEPR;
	  
	public BookMealSystemWB(String endpoint) throws AxisFault{
		  	serviceClient = new RPCServiceClient();
		    options = serviceClient.getOptions();
		    targetEPR = new EndpointReference(endpoint);
		    options.setTo(targetEPR);
	  }
	  
	  public Object[] invokeOp(String targetNamespace, String opName,
		      Object[] opArgs, Class
    
    [] opReturnType) throws AxisFault,
		      ClassNotFoundException {
		    // 设定操作的名称
		    QName opQName = new QName(targetNamespace, opName);
		    // 设定返回值
		    //Class
    
    [] opReturn = new Class[] { opReturnType };
		    // 操作需要传入的参数已经在参数中给定,这里直接传入方法中调用
		    return serviceClient.invokeBlocking(opQName, opArgs, opReturnType);
		  }
}
客户端调用代码【BookMealSystemClient.java】
package Book.BookMealSystem;

import org.apache.axis2.AxisFault;

public class BookMealSystemClient{
	
	public BookMealSystemClient(){
		
	}
	final private String endPointReference = "http://localhost:8080/axis2/services/BookMealSystem";
	final private String targetNamespace = "http://Service.Book";

	public String CancelBookMeal(String telephone){
		  try {
			BookMealSystemWB wBClient = new BookMealSystemWB(endPointReference);
			String opName = "CancelBookMeal";
			Object[] opArgs = new Object[]{telephone};
			
			Class
    
    [] opReturnType = new Class[]{String[].class};
		    Object[] response = wBClient.invokeOp(targetNamespace, opName, opArgs, opReturnType);
		    System.out.println(((String[])response[0])[0]);
		    
		    return ((String[])response[0])[0];
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	  }
	  
	  public String BookMeal(String wantDate, String telephone, String name){
		  try {
				BookMealSystemWB wBClient = new BookMealSystemWB(endPointReference);
				String opName = "BookMeal";
				Object[] opArgs = new Object[]{wantDate, telephone, name};
				
				Class
    
    [] opReturnType = new Class[]{String[].class};
			    Object[] response = wBClient.invokeOp(targetNamespace, opName, opArgs, opReturnType);
			    
			    System.out.println(((String[])response[0])[0]);
			    
			    return ((String[])response[0])[0];
			} catch (AxisFault e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
	  }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值