axis1,xfire,jUnit 测试案列+开Web Service开发指南+axis1.jar下载 代码

axis1,xfire,jUnit 测试案列+Web Service开发指南(中).pdf+axis1.jar下载    代码

项目和资源文档+jar 下载:http://download.csdn.net/detail/liangrui1988/5810873


项目内容:


部分主要代码:

axis1:

package com.webservice.test;

/**
 * @author liangrui
 * 
	1:把axis-bin-1_4.zip 解压后的axis文件拷贝到tomcat webpaas目录下
	2:直接把java文件拷贝到axis目录下 (是配置即时发部)
	3:定时发布,有包名.
	     需要把编译好的java文件 也就是class文件拷贝到你的axis/WEB-INF/class文件下;
	  然后在WEB-INF目录下新建一个deploy.wsdd文件:
	  
	  <deployment xmlns="http://xml.apache.org/axis/wsdd/" 
          xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
          <!--服务相关配置-->
	    <service name="helloworldWSDD" provider="java:RPC">
		 <parameter name="allowedMethods" value="*"/>
         <parameter name="className" value="com.webservice.service.HelloWorld"/>
		 <parameter name="scope" value="request"/>               
	   </service>
   </deployment>
	****************************这个是我提前做好的文件****************************
	deploy.wsdd\start_Services.bat文件拷贝到axis/WEB-INF下( 这个是配置 定时发布的)
	start_Services.bat //打开服务 《也可以在cmd下操作》
	***********************************************************************
  4:cmd方式:
	打开cmd cd到你tomcat目录下 axis WEB-INF下,输入命令:
	java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient deploy.wsdd
	//编译当前文件夹(WEB-INF)下的 deploy.wsdd文件,会生成一个server-config.wsdd文件
	
  5:浏览器访问的时候会根据你的请求名字 
	来找这个配制文件(server-config.wsdd) 里的service 节点下的name属性 ,
	再详细的解析==(也就是deploy.wsdd 文件	下的 <service name="xx" ....>)
	
	shutDown_Services.bat  //关闭服条 根打开服务操作一样
 *
 */

import java.rmi.RemoteException;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class Test {
	public static void main(String[] args) {
		
		jwsTest();// 即时发部
		
		deployTest(); //定时发布 部署,有包名
	
	}
	
	/**
	 * 即时发部
	 */
	public static void jwsTest(){
		try {
			// 访问的url
			String url="http://localhost:8080/axis/HelloWorld.jws";
			// 创建service
			Service service = new Service();
			// 通过service 创建call
			Call call =(Call) service.createCall();
			// 设置访问的webservice
			call.setTargetEndpointAddress(url);
			//调用指定方法
			call.setOperationName(new QName(url,"sayHello"));
			//传送参数 并返回结果
			String resource=(String) call.invoke(new Object[]{"accp157"});
			
			System.out.println("返回的数据:"+resource);
			
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 定时发布
	 */
	public static void deployTest(){
		// 访问的url
		// http://项目路径 /services/服务名称(需要和deploy.wsdd 中的service 配置一)
		String url ="http://localhost:8080/axis/services/helloworldWSDD";
		// 创建service
		Service service = new Service();
		try {
			// 创建call
			Call call = (Call) service.createCall();
			// 设置访问的url
			call.setTargetEndpointAddress(url);
			// 设置调用的webservice 的方法
			call.setOperationName(new QName(url,"jia"));
			// 执行
			int result = (Integer) call.invoke(new Object[]{2,3});
			// 执行结果
			System.out.println("结果是:"+result);
			
			call.setOperationName(new QName(url,"jian"));
			
			result = (Integer) call.invoke(new Object[]{2,3});
			
			System.out.println("结果是:"+result);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}

java文件

public class HelloWorld {
	public String sayHello(String name){
		System.out.println("hello:"+name);
		return "hello.."+name;
	}

}

有包的java文件

package com.webservice.service;

/**
 * 加减乘除
 * @author Administrator
 *
 */
public class HelloWorld {
	
	public int jia(int num1,int num2){
		return num1+num2;
	}
	public int jian(int num1,int num2){
		return num1-num2;
	}
	public int chen(int num1,int num2){
		return num1*num2;
	}
	public int chun(int num1,int num2){
		if(num2 > 0){
			return num1/num2;
		}else{
			return 0 ;
		}
	}
	
}

axis1 调用天气预报测试:

package com.webservice.test;

import java.rmi.RemoteException;


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;

import javax.xml.rpc.ServiceException;

public class ForecastTest {
	public static void main(String[] args) {
		
		 // http://WebXml.com.cn/是wsdl中definitions根节点的targetNamespace属性  
	      
	    // webservice路径   
	    // 这里后面加不加 "?wsdl" 效果都一样的  
	    String endpoint = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";          
	    String[] res = null;   
	      
	    // 查询城市天气的接口方法名   
	    String operationName = "getWeather";   
	    // 定义service对象  
	    Service service = new Service();   
	    // 创建一个call对象  
	    Call call = null;
		try {
			call = (Call) service.createCall();
		} catch (ServiceException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}   
	    // 设置目标地址,即webservice路径   
	    call.setTargetEndpointAddress(endpoint);   
	    // 设置操作名称,即方法名称   
	    call.setOperationName(new QName("http://WebXml.com.cn/",operationName));   
	    // 设置方法参数   
	    call.addParameter( new QName("http://WebXml.com.cn/","theCityCode"),  
	    org.apache.axis.encoding.XMLType.XSD_STRING,   
	    javax.xml.rpc.ParameterMode.IN);   
	    call.addParameter( new QName("http://WebXml.com.cn/","theUserID"),  
	            org.apache.axis.encoding.XMLType.XSD_STRING,   
	            javax.xml.rpc.ParameterMode.IN);   
	    // 设置返回值类型   
	    //对于返回是字符串数组的返回类型只有这两种可行  
	      
	    //call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_VECTOR);  
	    call.setReturnClass(java.lang.String[].class);  
	      
	    call.setUseSOAPAction(true);   
	    call.setSOAPActionURI("http://WebXml.com.cn/"+"getWeather");  
	      
	    String cityCode="广州";
	    String userId="";
	    try {
			res=(String[]) call.invoke(new Object[]{cityCode,userId});
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
	      
	    // 如果返回类型是org.apache.axis.encoding.XMLType.SOAP_VECTOR时用下面的转型接收  
	    //Vector v=(Vector) call.invoke(new Object[]{cityCode,userId});   
	    for(String str:res)  
	    {  
	        System.out.println(str);  
	    }  
	   // return res;  
	}  
	}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值