机器人 - 如何通过双重价值使用KSOAP到服务 [英] android -How to pass double value to service using ksoap
本文介绍了机器人 - 如何通过双重价值使用KSOAP到服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序,我想通过双值
到 Web服务
使用 KSOAP
,但我得到的 NPE
。在codeexit_distance的双重价值。任何机构可以找到的错误,并送样例如
code这里
//测试需要衣被合计
RB_Constant.RB_Webservice_URL =?
RB_Constant.RB_Webservice_Namespace =?
公共字符串getExitsRestaurants()抛出的SOAPFault
{
字符串数据=;
字符串的serviceUrl = RB_Constant.RB_Webservice_URL;
字符串serviceNamespace = RB_Constant.RB_Webservice_Namespace;
字符串的soapAction =http://www.roadbrake.com/GetExitDetailsExtn;
字符串type_of_soap =GetExitDetailsExtn;
尝试
{
SoapObject请求=新SoapObject(serviceNamespace,type_of_soap);
的PropertyInfo HighwayIdObj =新的PropertyInfo();
HighwayIdObj.name =HighwayId;
HighwayIdObj.type = PropertyInfo.INTEGER_CLASS;
Request.addProperty(ExitNo,7);
Request.addProperty(HighwayIdObj,highwayid);
Request.addProperty(HighwayName,95);
Request.addProperty(exit_distance,1.2);
的System.out.println(请求价值 - >中+ Request.toString());
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = TRUE;
MarshalDouble MD =新MarshalDouble();
md.register(信封);
envelope.setOutputSoapObject(请求);
尝试
{
HttpTransportSE androidHttpTransport =新HttpTransportSE(的serviceUrl);
androidHttpTransport.call(的soapAction,包);
}
赶上(例外五)
{
的System.out.println(web服务调用错误 - >中+ e.toString());
}
SoapPrimitive响应=(SoapPrimitive)envelope.getResponse();
数据= response.toString();
的System.out.println(web服务响应 - >中+ response.toString());
}
赶上(例外五)
{
的System.out.println(SOAP方法错误 - >中+ e.toString());
}
返回的数据;
}
公共类MarshalDouble实现元帅
{
@覆盖
公共对象readInstance(XmlPullParser分析器,字符串空间,字符串名称,
的PropertyInfo预期)抛出IOException异常,XmlPullParserException {
返回Double.parseDouble(parser.nextText());
}
公共无效寄存器(SoapSerializationEnvelope厘米){
cm.addMapping(cm.xsd,exit_distance,Double.class,这一点);
}
@覆盖
公共无效writeInstance(XmlSerializer的作家,obj对象)抛出IOException异常{
writer.text(obj.toString());
}
}
解决方案
要准确使用这样
Marshal类
进口org.ksoap2.serialization.Marshal;
进口org.ksoap2.serialization.PropertyInfo;
进口org.ksoap2.serialization.SoapSerializationEnvelope;
进口org.xmlpull.v1.XmlPullParser;
进口org.xmlpull.v1.XmlPullParserException;
进口org.xmlpull.v1.XmlSerializer;
进口java.io.IOException异常;
公共类MarshalDouble实现元帅{
公共对象readInstance(XmlPullParser分析器,字符串空间,字符串名称,
的PropertyInfo预期)抛出IOException异常,XmlPullParserException {
返回Double.parseDouble(parser.nextText());
}
公共无效寄存器(SoapSerializationEnvelope厘米){
cm.addMapping(cm.xsd,双,Double.class,这一点);
}
公共无效writeInstance(XmlSerializer的作家,obj对象)抛出IOException异常{
writer.text(obj.toString());
}
}
执行
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = TRUE;
envelope.dotNet = TRUE;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.setOutputSoapObject(要求);
** MarshalDouble MD =新MarshalDouble();
md.register(信封)**
In My application i want to pass the double value
to the web service
using ksoap
but i am getting the NPE
. In the code "exit_distance" is double value. can any body find the error in that and send the sample example
code here
//valus required for test
RB_Constant.RB_Webservice_URL = ?
RB_Constant.RB_Webservice_Namespace = ?
public String getExitsRestaurants() throws SoapFault
{
String data = "";
String serviceUrl = RB_Constant.RB_Webservice_URL;
String serviceNamespace = RB_Constant.RB_Webservice_Namespace;
String soapAction = "http://www.roadbrake.com/GetExitDetailsExtn";
String type_of_soap = "GetExitDetailsExtn";
try
{
SoapObject Request = new SoapObject(serviceNamespace, type_of_soap);
PropertyInfo HighwayIdObj = new PropertyInfo ();
HighwayIdObj.name = "HighwayId";
HighwayIdObj.type = PropertyInfo.INTEGER_CLASS;
Request.addProperty("ExitNo", 7);
Request.addProperty(HighwayIdObj, highwayid);
Request.addProperty("HighwayName", 95);
Request.addProperty("exit_distance", 1.2);
System.out.println("Request Value->"+Request.toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
MarshalDouble md = new MarshalDouble();
md.register(envelope);
envelope.setOutputSoapObject(Request);
try
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(serviceUrl);
androidHttpTransport.call(soapAction, envelope);
}
catch(Exception e)
{
System.out.println("Webservice calling error ->"+e.toString());
}
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
data = response.toString();
System.out.println("web service response->"+response.toString());
}
catch(Exception e)
{
System.out.println("Soap Method Error ->"+e.toString());
}
return data;
}
public class MarshalDouble implements Marshal
{
@Override
public Object readInstance(XmlPullParser parser, String namespace, String name,
PropertyInfo expected) throws IOException, XmlPullParserException {
return Double.parseDouble(parser.nextText());
}
public void register(SoapSerializationEnvelope cm) {
cm.addMapping(cm.xsd, exit_distance, Double.class, this);
}
@Override
public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
writer.text(obj.toString());
}
}
解决方案
To be exact use it like this
the Marshal class
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
public class MarshalDouble implements Marshal {
public Object readInstance(XmlPullParser parser, String namespace, String name,
PropertyInfo expected) throws IOException, XmlPullParserException {
return Double.parseDouble(parser.nextText());
}
public void register(SoapSerializationEnvelope cm) {
cm.addMapping(cm.xsd, "double", Double.class, this);
}
public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
writer.text(obj.toString());
}
}
the implementation
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.setOutputSoapObject(request);
**MarshalDouble md = new MarshalDouble();
md.register(envelope);**
这篇关于机器人 - 如何通过双重价值使用KSOAP到服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文