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 ...
随机推荐
- wifi连接android设备进行调试
手机下载终端模拟器: 并输入例如以下$ su # setprop service.abd.tcp.port 5555 # stop adbd # start adbd 在cmd中输入adb conne ...
- php内置的http server, 类似于nodejs里面和golang里面的
原文:https://www.sitepoint.com/taking-advantage-of-phps-built-in-server/ ----------------------------- ...
- 微信公众帐号开发教程第4篇-----开发模式启用及接口配置Java
欢迎加入群:347245650 345531810 进行讨论相互交流 我的微信号:572839485 我的微信公众账号 我的微社区欢迎关注 索取源码←请点击 图床:没有服务器 拖拽图片 外网即 ...
- ASP.NET Core Kestrel 随机404错误
一.Bug 出现 最近遇到一个很诡异的bug,Visual Studio 2017调试ASP.NET Core 2.2 Web程序的时候,随机性的出现404错误.如下图 事实上这个css文件是存在的, ...
- NSURLConnection经常使用的代理方法
NSURLConnection的代理Protocol定义有三类:NSURLConnectionDelegate.NSURLConnectionDataDelegate和NSURLConnectionD ...
- (转)android适配各种分辨率的问题
Android设备屏幕的尺寸是各式各样的,如小米是4英寸的,Xoom平板是10英寸:分辨率也千奇百怪,800×480,960×540等:Android版本的碎片化问题更是萦绕于心,不过在设计应用时可以 ...
- 【LeetCode】63. Unique Paths II
Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are added to ...
- JAVA变量的执行顺序
对于静态变量.静态初始化块.变量.初始化块.构造器,它们的初始化顺序以此是(静态变量.静态初始化块)>(变量.初始化块)>构造器.我们也可以通过下面的测试代码来验证这一点: package ...
- C#:设置控件样式(待补充)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- MySQL Subquery
Summary: in this tutorial, we will show you how to use the MySQL subquery to write complex queries a ...