WebService 通用接收方法
/**
* @Title: getNetStatusRequest
* @Description: TODO(2.1检查网络状态字符串)
* @param:
* @return: String
* @throws
*/
/*拼接xml字符串用,里面域名和参数需要根据具体需求进行修改*/
private static String getSOAPRequest(String information){
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+ "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+"<soap:Body>"+"******"+
"</soap:Body></soap:Envelope>");
return sb.toString();
}
/*得到流*/
public static InputStream getSoapInputStream(String infor){
try {
String soap = getSOAPRequest(infor);
URL url = new URL(
"http://service.smart-health.cn/DeviceWebService.asmx");
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Length",
Integer.toString(soap.length()));
conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
conn.setRequestProperty("SOAPAction",
"域名");
OutputStream os = conn.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os, "utf-8");
osw.write(soap);
osw.flush();
osw.close();
// 获取webserivce返回的流
InputStream is = conn.getInputStream();
return is;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/*根据流获取需要内容*/
public static String getHealth(String healthInfor){
try {
Document doc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = getSoapInputStream(healthInfor);
doc = db.parse(getSoapInputStream(healthInfor));
NodeList nl = doc.getElementsByTagName("包含特殊内容的标签名");
StringBuffer sb = new StringBuffer();
for (int count = 0; count < nl.getLength(); count++) {
Node n = nl.item(count);
if(n.hasChildNodes()){
if (n.getFirstChild().getNodeValue().isEmpty()) {
sb = new StringBuffer("#");
break;
}
// 解析并以"#"为分隔符,拼接返回结果
sb.append(n.getFirstChild().getNodeValue() + "#");
}else{
sb.append("对不起,没有您的健康数据!#"+ConvertUtil.convertStreamToString(getSoapInputStream(healthInfor)));
}
}
is.close();
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
WebService 通用接收方法的更多相关文章
- 动态调用WebService 通用方法Moss 中 传统开发中都可用。
WebService是啥大家都知道了,这里不做过多的解释.通常我们使用WebService的做法基本都是在我们的项目中添加Web引用的方式,首先找到WebService的地址,然后定义命名空间,这样会 ...
- java 调用webservice的各种方法总结
java 调用webservice的各种方法总结 几种流行的开源WebService框架Axis1,Axis2,Xfire,CXF,JWS比较 方法一:创建基于JAX-WS的webservice(包括 ...
- WebService服务调用方法介绍
1 背景概述 由于在项目中需要多次调用webservice服务,本文主要总结了一下java调用WebService常见的6种方式,即:四种框架的五种调用方法以及使用AEAI ESB进行调用的方法. 2 ...
- WebForm和WinForm取当前根目录的通用的方法[转载]
转自:WebForm和WinForm取当前根目录的通用的方法 某些环境下用 System.Web.HttpContext.Current.Server.MapPath 取不到目录. 可以用下面两个方法 ...
- Entity Framework增删改之通用精简方法
用EF用了好长一段时间了,从EF4.0的版本开始接触,感觉这个ORM不能说性能是最好的,但是我个人感觉功能实现以及和mvc的结合还是一个不错的企业级网站的解决方案,在此写个简易的通用扩展方法来方便大家 ...
- Java高效编程之二【对所有对象都通用的方法】
对于所有对象都通用的方法,即Object类的所有非final方法(equals.hashCode.toString.clone和finalize)都有明确的通用约定,都是为了要被改写(override ...
- [Effective Java]第三章 对所有对象都通用的方法
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- MVC LINQ中用封装的TSQL通用更新方法
把TSQL拿出来,做了一个封装,适用的所有表,更新有两种,普通更新和记数更新 看代码:这两个方法是写在DAL里的数据操作基类里的,只有它的子类可以用它,所以用protected做为限制 /// < ...
- 关于webservice不支持方法重载的解决办法
今天在写WebService时,出现了这样的错误: Count(Int32, Int32) 和 Count(Int32) 同时使用消息名称“Count”.使用 WebMethod 自定义特性的 Mes ...
随机推荐
- UILabel+Create
#import <UIKit/UIKit.h> @interface UILabel (Create) /** * 创建普通Label * * @param frame frame * @ ...
- C库函数笔记
一.string.h 1.memcpy 函数原型:void *memcpy(void *dest, const void *src, size_t n); 功能:从源src所指的内存地址的起始位置开始 ...
- 本博客弃用,请移步http://ningios.com查看最新
本博客弃用,请移步http://ningios.com查看最新
- javascript 获取event对象
//转载处 http://www.cnblogs.com/funlake/archive/2009/04/07/1431238.html 非常详细 先从一个简单的例子说起,一个简单的button控件如 ...
- mysql忘记密码时如何修改root用户密码
1.关闭正在运行的MySQL服务. 2.打开DOS窗口,转到mysql\bin目录. 3. 输入mysqld --skip-grant-tables 回车.--skip-grant-tables 的意 ...
- css 梯形标签页
html 代码 略 css : nav > a{ position: relative; display: inline_block; padding: .3em 1em 0; } nav &g ...
- easyui page添加文本,js验证码
onLoadSuccess: function (db) { //db是后台数据的返回结果集 $.ajax({ url: "AjaxSource/Buex.ashx", data: ...
- 在JS中得到表单中各项的值
var form = document.getElementById("change");var pageNo = form.pageno.value;
- 使用nextInt()等接受输入时必须注意换行符的输入
参考http://stackoverflow.com/questions/19331426/for-loop-does-not-iterate-the-way-i-want 见以下代码: packag ...
- php的一些小笔记--数学函数
通常我们使用的数学函数不多,经常出现的有 floor 地板->舍去 ceil 天花板->进一 round 四舍五入 rand 随机数 mt_rand 产生更好的随机数 pow 指数表达 ...