Android– 如何向ws服务发送double值

Android– 如何向ws服务发送double值,第1张

概述我试图使用kso​​ap库向Web服务发送一个double值.这是我尝试过的,但它不起作用.任何人都可以解释如何使这项工作.publicStringgetDataForStaticSearch()throwsSoapFault{Stringdata="";StringserviceUrl=RB_Constant.RB_Webservice_URL;String

我试图使用kso​​ap库向Web服务发送一个double值.
这是我尝试过的,但它不起作用.任何人都可以解释如何使这项工作.

public String getDataForStaticSearch() throws SoapFault   {      String data = "";    String serviceUrl = RB_Constant.RB_Webservice_URL;    String servicenamespace = RB_Constant.RB_Webservice_namespace;     String soapAction = "http://www.roadbrake.com/GetSearchResultsV2";    String type_of_soap = "GetSearchResultsV2";      PropertyInfo headingdirectionObj = new PropertyInfo ();    headingdirectionObj.name = "headingdirection";    headingdirectionObj.type = PropertyInfo.INTEGER_CLASS;      try    {        SoapObject Request = new SoapObject(servicenamespace, type_of_soap);        //  strUserLatitude and strUserLongitude are of type double.        // How to pass these values to ws.          Request.addProperty("strUserLatitude", 33.924012);                  Request.addProperty("strUserLongitude", -118.3832772);         //headingdirectionObj is of type int        Request.addProperty(headingdirectionObj, 0);        System.out.println("Request Value->"+Request.toString());        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);        envelope.dotNet = true;        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;}

解决方法:

准确地使用它就像这样

元帅阶级

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 implementationSoapSerializationEnvelope 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);**
总结

以上是内存溢出为你收集整理的Android – 如何向ws服务发送double值全部内容,希望文章能够帮你解决Android – 如何向ws服务发送double值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1109741.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存