Java调用doNet webService方法
doNet的webService
浏览器访问测试地址:http://192.168.4.17/JLWWS/sendCommand.asmx,出现

点击getDeviceValue方法,出现

上图的xml代码再贴一遍:
POST /JLWWS/sendCommand.asmx HTTP/1.1
Host: 192.168.4.17
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/getDeviceValue" <?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>
<getDeviceValue xmlns="http://tempuri.org/">
<n>int</n>
<s>string</s>
</getDeviceValue>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length <?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>
<getDeviceValueResponse xmlns="http://tempuri.org/">
<getDeviceValueResult>string</getDeviceValueResult>
</getDeviceValueResponse>
</soap:Body>
</soap:Envelope>
然后 java方法:
public String cc(){
String result = "";
try{
Service service = new Service();
Call call = (Call) service.createCall();
call.setOperationName(new QName("http://tempuri.org/", "getDeviceValue"));
call.addParameter(new QName("http://tempuri.org/", "n"), org.apache.axis.encoding.XMLType.XSD_INT, javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName("http://tempuri.org/", "s"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setTargetEndpointAddress(new URL("http://192.168.4.17/JLWWS/sendCommand.asmx"));
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://tempuri.org/getDeviceValue");
//SOAPService soap = new SOAPService();
//soap.setName("sendCommand1");
//call.setSOAPService(soap);
result = (String) call.invoke(new Object[] { "1", "aaaaaaaaa"});
System.out.println(result);
}catch(Exception e){
e.printStackTrace();
}
return result;
}
注意上述代码的红色部分。第一、命名空间注意不要写错了;第二、参数如果是int类型的话,设置值的时候用String的方式入参,(addParameter的时候还是要org.apache.axis.encoding.XMLType.XSD_INT)。
参考csdn论坛上有个帖子是这么说的:
错误信息如下:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
faultSubcode:
faultString: 服务器无法读取请求。 ---> XML 文档(1, 582)中有错误。 ---> 输入字符串的格式不正确。
==================
虽然xml中是
<soap:Body>
<PubClientLogin xmlns="http://NewCap.com/NewCapecWebService/">
<appid>int</appid>
</PubClientLogin>
</soap:Body>
但是传入参数要输入string类型,
call.addParameter(new QName(targetNameSpace, "appid"), XMLType.XSD_INT, ParameterMode.IN);
call.invoke(new Object[]{""})
帖子地址:http://bbs.csdn.net/topics/360243982
Java调用doNet webService方法的更多相关文章
- Java调用.NET webservice方法的几种方式
最近做项目,涉及到web-service调用,现学了一个星期,现简单的做一个小结.下面实现的是对传喜物流系统(http://vip.cxcod.com/PodApi/GetPodStr.asmx?ws ...
- Java调用.Net WebService参数为空解决办法 (远程)调试webservice方法 转
Java调用.Net WebService参数为空解决办法 (远程)调试webservice方法 同事遇到一个很囧的问题,java调,netwebservice的时候,调用无参数方法成功,调用有参 ...
- java调用C# webService发布的接口
java调用C# webService发布的接口 java调用C# webService方式有很多种我这里只介绍一种 首先需要引入axis的jar包 axis的maven坐标如下 <depend ...
- 调用具体webservice方法时时报错误:请求因 HTTP 状态 503 失败: Service Temporarily Unavailable
添加web引用会在相应项目的app.cofig文件中产生如下代码: <sectionGroup name="applicationSettings" type="S ...
- android ksoap2调用.net Webservice 方法总结
android ksoap2调用.net Webservice 方法直接放到一个类里: package com.util; import org.ksoap2.SoapEnvelope; impor ...
- Android-WebView与本地HTML (Java调用--->HTML的方法)-(new WebView(this)方式)
之前的博客,Android-WebView与本地HTML (Java调用--->HTML的方法),是在 findViewById(R.id.webview);,来得到WebView, 此博客使用 ...
- Android-WebView与本地HTML (Java调用--->HTML的方法)
上一篇博客 Android-WebView与本地HTML (HTML调用-->Java的方法) 介绍了 JavaScript 调用--> Java中的方法,而此篇博客是介绍 Java 调用 ...
- Java调用.Net WebService参数为空解决办法 (远程)调试webservice方法
同事遇到一个很囧的问题,java调,netwebservice的时候,调用无参数方法成功,调用有参数的方法每次我这边的webservice日志都记录参数为空,而我自己.Net程序调用完全没有问题,后面 ...
- JAVA调用.NET WebService终极方案(包含对SoapHeader的处理)
一.前言: 今日部门的产品需要用到短信功能,需要走公司统一的接口,而该短信接口是由.net开发的,利用两天时间彻底搞定了用java来调用.net 的web service,包括对soap h ...
随机推荐
- 水晶报表WEB方式下不打印的问题
水晶报表版本是10.2.3600.0,是vs2005自带的.功能原来正常,服务器重做后不能打印,但是导出功能正常. 研究的大概情况: 1.水晶报表的web相关代码位于\aspnet_client\sy ...
- (剑指Offer)面试题44:扑克牌的顺子
题目: 从扑克牌中随机抽5张牌,判断是不是一个顺子,即这五张牌是不是连续的,2~10为数字本身,A为1,J为11,Q为12,K为13,而大小王可以看成任意数字. 思路: 把5张牌看成一个数组,就看排序 ...
- share_ptr
1.为了保证不会重复释放内存,auto_ptr的copy构造和copy赋值都是破坏性操作,执行后,导致右操作数的指针为0.这就出现了,copy构造或者copy赋值后,两个对象不相等了. 2.auto_ ...
- Units specified don't exist SHSUCDX can't install
重装系统,出现“Units specified don't exist SHSUCDX can't install”怎么办? 昨天,我们领导弄了个联想Thinkpad T510i的笔记本,本来预装的是 ...
- gem 更新源设置,ruby安装
gem sources --remove http://rubygems.org/ gem sources -a http://ruby.taobao.org/ gem sources -l 结果只有 ...
- Decorator Pattern (装饰者模式)
装饰者模式( Decorator Pattern ) 意图 : 动态的给一个对象添加一些额外的功能,IO这块内容体现出了装饰模式,Decorator模式相比生成子类更为灵活. 角色 : 1)抽象构件角 ...
- OPENERP 构建动态视图
来自:http://shine-it.net/index.php/topic,16142.0.html 在openerp展示界面通常是通过定义class的view(xml文件)来实现的. 有时这种方法 ...
- 如何知道TSQL语句已经运行了多久
如何知道TSQL语句已经运行了多久 ,) --millisecond per tick --如果datediff 函数导致溢出 把下面的millisecond改为second 毫秒改为秒 SELECT ...
- oracle 存储过程 调用动态sql
oracle 存储过程 调用动态sql CreationTime--2018年8月16日11点25分 Author:Marydon 1.错误实现方式 --开始时间拼接' 00:00:00' V_S ...
- LeetCode-2: Add Two Numbers
[Problem:2-Add Two Numbers] You are given two non-empty linked lists representing two non-negative i ...