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

标签 android ksoap

我正在尝试使用 ksoap 库向 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;
}

最佳答案

准确的说是这样使用

编码(marshal)级

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);**

关于Android - 如何向 ws 服务发送 double 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9373600/

相关文章:

.net - Web 服务使用 ksoap 方法从应用程序接收空参数

android - KSOAP2 : get http status code for a response of a web service

android - 在 Mac 上的真实设备上测试 Android 项目时,我的 URL localHost 是什么?

android - 如何以编程方式打开 Android Play 商店设置页面

android - getAllCellInfo() 在 Nexus 5x 上返回空列表

java - 如何在我的 Kotlin 类中创建匿名接口(interface)实现并使用它?

android - 如何在 android 中使用 Ksoap2 将 json 数组作为参数传递给 Web 服务

android - 将 Google map 与抽屉导航和 viewpager 一起使用会崩溃

android - 如何更改 pjsip android 中的编解码器优先级

Android KSOAP2 SSL java.security.cert.CertPathValidatorException