点击上面 免费订阅本账号!
本公众号主要推送javaweb开发相关技术,基础知识点,同时会深入剖析复杂的问题,分享一些优秀的框架,大型项目经验,当今最流行的Javaweb技术,热点科技新闻,招聘信息,生活乐趣等等。点击上方的蓝字,这样您每天可以看到更多的java知识和资讯!完全是免费订阅,请放心关注。
第五步、sping配置文件(Spring-axis.xml)配置bean(项目位置/WEB-INF/config/context/Spring-axis.xml)
[html] view plain copy
<?xml version="1.0" encoding="UTF-8"?>
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="testWebService" class="com.business.apps.manager.impl.TestWebServiceImpl" />
</beans>
第六步、web.xml里配置sping容器
[html] view plain copy
<!-- spring容器配置 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/context/Spring-axis.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
第七步、调试无错误后之后启动eclipse,在浏览器里输入 http://localhost:8080/services/WebService?wsdl 有xml显示后编写调用接口类
testWebServiceGet.java
[java] view plain copy
/**
*
*/
package com.business.apps;
/**
* @author
* @version 创建时间:2017年1月5日 下午5:35:26
*
*/
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import javax.xml.namespace.QName;
import net.sf.json.JSONObject;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class testWebServiceGet {
private String nameSpaceUri = "http://localhost:8080/services/WebService";
//private String nameSpaceUri = "http://www.ntrl.gov.cn/services/WebService";
private String wsdlUrl = nameSpaceUri + "?wsdl";
private Service service;
private Call call;
public final void init() throws Exception {
// 创建调用对象
service = new Service();
call = (Call) service.createCall();
// 调用 远程方法
call.setOperationName(new QName(nameSpaceUri, "getStr"));
// 设置URL
call.setTargetEndpointAddress(new URL(nameSpaceUri));
}
public final void testGet() throws Exception {
Map<String, String> result = new HashMap<String, String>();
result.put("urlInput","http://www.google.com");
JSONObject json = JSONObject.fromObject(result);
String jsonString =json.toString();
// 执行远程调用,同时获得返回值
String r = (String) call.invoke(new Object[] {jsonString});
JSONObject jsons = JSONObject.fromObject(r);
String jsonStrings =jsons.toString();
System.out.println("jsonStrings=" + jsonStrings);
}
public static void main(String[] args) {
testWebServiceGet test = new testWebServiceGet();
try {
test.init();
test.testGet();
} catch (Exception e) {
e.printStackTrace();
}
}
}
点击阅读全文阅读"实例分析:关于Web设计的原则与体会”
有人用微信聊天,有人却在微信中学习,成长。下面是2016最HOT IT公众号,赶快试试新的关注方法吧!
关注方式
★长按二维码,选择“识别图中二维码”进行关注。