2012-02-21 12 views
3

我想發送一個雙重值的web服務使用kso​​ap庫。 這是我試過的,但它不起作用。任何人都可以解釋如何使這項工作。Android - 如何發送一個雙重值的ws服務

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; 
} 
+0

請什麼ü做了..... – 2012-02-21 07:33:28

+0

我更新了帖子,請參閱該 – naresh 2012-02-21 09:00:14

+0

提供一些細節@naresh我也需要將緯度和長度的double值發送到WSDL服務並獲得內部服務錯誤異常。你能幫我解決嗎? – 2014-07-10 05:36:45

回答

5

要確切使用這樣

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

我不知道誰的白癡誰downvoted我的文章沒有留言!? – IamStalker 2013-01-10 13:26:26

+0

這對我有用,我會upvote它,提問者應該接受它。 – 2013-07-02 13:49:04

+0

@NemanjaKovačević那麼,你爲什麼不喜歡它;)? – IamStalker 2013-07-03 10:11:53

相關問題