详解spring+webservice接口(axis1方式)(下)

点击上面  免费订阅本账号!

本公众号主要推送javaweb开发相关技术,基础知识点,同时会深入剖析复杂的问题,分享一些优秀的框架,大型项目经验,当今最流行的Javaweb技术,热点科技新闻,招聘信息,生活乐趣等等。点击上方的蓝字,这样您每天可以看到更多的java知识和资讯!完全是免费订阅,请放心关注。

第五步、sping配置文件(Spring-axis.xml)配置bean(项目位置/WEB-INF/config/context/Spring-axis.xml)

[html] view plain copy

  1. <?xml version="1.0" encoding="UTF-8"?>  

  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  

  3.     xsi:schemaLocation="http://www.springframework.org/schema/beans  

  4.                                              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  

  5.                                              http://www.springframework.org/schema/context  

  6.                                              http://www.springframework.org/schema/context/spring-context-3.0.xsd">  

  7.       

  8.   

  9.       <bean   id="testWebService"   class="com.business.apps.manager.impl.TestWebServiceImpl" />    

  10.   

  11.   

  12.       

  13. </beans>  

第六步、web.xml里配置sping容器

[html] view plain copy

  1. <!-- spring容器配置 -->  

  2.     <listener>  

  3.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  

  4.     </listener>  

  5.     <context-param>  

  6.         <param-name>contextConfigLocation</param-name>  

  7.         <param-value>           

  8.             /WEB-INF/config/context/Spring-axis.xml  

  9.         </param-value>  

  10.     </context-param>  

  11.   

  12.     <listener>  

  13.         <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  

  14.     </listener>  


第七步、调试无错误后之后启动eclipse,在浏览器里输入 http://localhost:8080/services/WebService?wsdl 有xml显示后编写调用接口类

testWebServiceGet.java

[java] view plain copy

  1. /** 

  2.  *  

  3.  */  

  4. package com.business.apps;  

  5.   

  6. /** 

  7.  * @author  

  8.  * @version 创建时间:2017年1月5日 下午5:35:26  

  9.  *  

  10.  */  

  11.   

  12. import java.net.URL;  

  13. import java.util.HashMap;  

  14. import java.util.Map;  

  15. import java.util.Random;  

  16.   

  17. import javax.xml.namespace.QName;  

  18.   

  19. import net.sf.json.JSONObject;  

  20.   

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

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

  23.   

  24.   

  25. public class testWebServiceGet {  

  26.   

  27.     private String nameSpaceUri = "http://localhost:8080/services/WebService";  

  28.     //private String nameSpaceUri = "http://www.ntrl.gov.cn/services/WebService";  

  29.     private String wsdlUrl = nameSpaceUri + "?wsdl";  

  30.   

  31.     private Service service;  

  32.     private Call call;  

  33.   

  34.     public final void init() throws Exception {  

  35.         // 创建调用对象  

  36.         service = new Service();  

  37.         call = (Call) service.createCall();  

  38.   

  39.         // 调用 远程方法  

  40.         call.setOperationName(new QName(nameSpaceUri, "getStr"));  

  41.         // 设置URL  

  42.         call.setTargetEndpointAddress(new URL(nameSpaceUri));  

  43.     }  

  44.   

  45.   

  46.       

  47.     public final void testGet() throws Exception {  

  48.   

  49.    

  50.         Map<String, String> result = new HashMap<String, String>();  

  51.         result.put("urlInput","http://www.google.com");  

  52.         JSONObject json = JSONObject.fromObject(result);  

  53.         String jsonString =json.toString();                               

  54.   

  55.         // 执行远程调用,同时获得返回值  

  56.         String r = (String) call.invoke(new Object[] {jsonString});  

  57.         JSONObject jsons = JSONObject.fromObject(r);  

  58.         String jsonStrings =jsons.toString();     

  59.         System.out.println("jsonStrings=" + jsonStrings);  

  60.   

  61.     }  

  62.   

  63.   

  64.     public static void main(String[] args) {  

  65.           

  66.         testWebServiceGet test = new testWebServiceGet();  

  67.     try {  

  68.             test.init();  

  69.             test.testGet();  

  70.         } catch (Exception e) {  

  71.             e.printStackTrace();  

  72.     }  

  73.     }  

  74.   

  75.       

  76.   

  77. }  

点击阅读全文阅读"实例分析:关于Web设计的原则与体会”

有人用微信聊天,有人却在微信中学习,成长。下面是2016最HOT IT公众号,赶快试试新的关注方法吧!


关注方式
★长按二维码,选择“识别图中二维码”进行关注。

 没看够?更多好文在阅读原文

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值