3

I am trying to send a double value to the web service using ksoap library. This is what I tried, but it doesn't work. Can anybody explain how to make this work.

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;
}
5
  • Please Provide some details with what u have done..... Feb 21, 2012 at 7:33
  • i updated the post please refer that
    – naresh
    Feb 21, 2012 at 9:00
  • @naresh I too need to send the double values of lat and long to the WSDL servieces and getting an Internal Service Fault Exception. Can you please help me in this ? Jul 10, 2014 at 5:36
  • I have used your marshal class, but how to implement it in my values ? Jul 10, 2014 at 5:37
  • @nareshCan you help me please Jul 10, 2014 at 7:33

1 Answer 1

6

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);**
6
  • 1
    I wonder whos the idiot who downvoted my post without leaving a message!?
    – hackp0int
    Jan 10, 2013 at 13:26
  • I did, but it was -1 right? Should I send you a screenshot? :) Jul 3, 2013 at 12:06
  • @IamStalker I have used your marshal class, but how to implement it in my values. I want to send Latitude and Longitude as parameters, and unable to get the response from the service, can you please help me Jul 10, 2014 at 6:16
  • Can you see the envelope? I've just had to register it and that's it.
    – hackp0int
    Jul 10, 2014 at 7:37
  • After one week of headache finally found a solution :)
    – mes
    Mar 12, 2015 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.