2012-06-22 81 views
1

您好我有一個問題相關到Android KSOAP,我第一次與KSOAP Android平臺KSOAP ANDROID實施

this is the service link

在這裏你可以看到請求和響應,也提到有, 這裏是我的代碼打到服務和獲取響應` 包com.ksoap.net;

import org.ksoap2.SoapEnvelope; 
    import org.ksoap2.serialization.PropertyInfo; 
    import org.ksoap2.serialization.SoapObject; 
    import org.ksoap2.serialization.SoapPrimitive; 
    import org.ksoap2.serialization.SoapSerializationEnvelope; 
    import org.ksoap2.transport.AndroidHttpTransport; 
    import org.ksoap2.transport.HttpTransportSE; 

    import android.app.Activity; 
    import android.os.Bundle; 
    import android.util.Log; 
    import android.widget.TextView; 

public class AndroidWebService extends Activity { 

     private final String NAMESPACE = "http://webservices.iyogi.net/"; 
                          private                     final                  String                URL             =           "http://sdservices.iyogi.net    /iyogi   /webservicesnonrestv5/toolbarwebservices.asmx"; 
     private final String SOAP_ACTION = "http://webservices.iyogi.net/GetSubscriptionByInputObject"; 
     private final String METHOD_NAME = "GetSubscriptionByInputObject"; 
     String request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" 
       + "<soap:Envelope " 
       + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " 
       + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " 
       + "xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">" 
       + "<soap:Body>" 
       + "<GetSubscriptionByInputObject xmlns=\"http://webservices.iyogi.net\">" 
       + "<inpAccessCode>" + "<AccessCode>」2466276627755434」</AccessCode>" 
       + "</inpAccessCode>" + "</GetSubscriptionByInputObject>" 
       + "</soap:Body>" + "</soap:Envelope>"; 

     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 

      // SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

      String weight = "3700"; 
      String fromUnit = "Grams"; 
      String toUnit = "Kilograms"; 


      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11); 
      envelope.dotNet = true; 
      envelope.setOutputSoapObject(request); 
      AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
        URL); 

      try { 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       SoapObject response = (SoapObject) envelope.getResponse(); 
       int result = Integer.parseInt(response.getProperty(0).toString()); 
       System.out.println("result is " + Integer.toString(result)); 
       System.out.println("res is -->> " 
         + response.getProperty(0).toString()); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
}` 

請幫我打,並得到從這項服務中 任何幫助,高度讚賞

回答

0
final String URL = "url"; 
       u = new java.net.URL(URL); 

      URLConnection uc = u.openConnection(); 
      connection = (HttpURLConnection) uc; 

      connection.setDoOutput(true); 
      connection.setDoInput(true); 
      connection.setRequestProperty("SOAPAction", SOAP_ACTION); 
      connection.setRequestMethod("POST"); 
      connection.setRequestProperty("Content-type", "text/xml; charset=utf-8"); 

      String xmldata ="xml request"; 


      //System.out.println(xmldata); 
      OutputStream out = connection.getOutputStream(); 

      Writer wout = new OutputStreamWriter(out); 

       wout.write(xmldata); 

       wout.flush(); 

       wout.close(); 
       InputStream is = connection.getInputStream(); 
       MakeHttpRequest.actiovationParser(is,AndroidWebService.this); 

,它工作很好 歡呼聲快樂編碼

0

正確的反應試試這個 `

import org.ksoap2.SoapEnvelope; 
     import org.ksoap2.serialization.PropertyInfo; 
     import org.ksoap2.serialization.SoapObject; 
     import org.ksoap2.serialization.SoapPrimitive; 
     import org.ksoap2.serialization.SoapSerializationEnvelope; 
     import org.ksoap2.transport.AndroidHttpTransport; 
     import org.ksoap2.transport.HttpTransportSE; 

     import android.app.Activity; 
     import android.os.Bundle; 
     import android.util.Log; 
     import android.widget.TextView; 

    public class AndroidWebService extends Activity { 

      private final String NAMESPACE = "http://webservices.iyogi.net/"; 
                           private                     final                  String                URL             =           "http://sdservices.iyogi.net    /iyogi   /webservicesnonrestv5/toolbarwebservices.asmx"; 
      private final String SOAP_ACTION = "http://webservices.iyogi.net/GetSubscriptionByInputObject"; 
      private final String METHOD_NAME = "GetSubscriptionByInputObject"; 
    private final String URL = "http://sdservices.iyogi.net/iyogi/webservicesnonrestv5/toolbarwebservices.asmx"; 

HttpTransportSE httpTransport = null; 

     SoapObject request = null; 
    request = new SoapObject(NAMESPACE, METHOD_NAME); 
      PropertyInfo pi = new PropertyInfo();  
      pi.setName("AccessCode"); 
      pi.setValue("2466276627755434"); 
      pi.setType(PropertyInfo.STRING_CLASS); 
      request.addProperty(pi); 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11); 
      envelope.dotNet = true; 

      envelope.setOutputSoapObject(request); 

      httpTransport = new HttpTransportSE(URL); 
      httpTransport.debug = true; 


      try { 
       httpTransport.call(SOAP_ACTION, envelope); 

    SoapObject response = (SoapObject) envelope.getResponse(); 
        int result = Integer.parseInt(response.getProperty(0).toString()); 
        System.out.println("result is " + Integer.toString(result)); 
        System.out.println("res is -->> " 
          + response.getProperty(0).toString()); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 

`

+0

感謝您的寶貴回覆 我得到06-22 11:43:48.588:警告/ System.err(671):SoapFault - faultcode:'肥皂:服務器'faultstring:'服務器無法處理請求。 --->對象引用未設置爲對象的實例。' faultactor:「空」的細節:[email protected] 問題,我們該如何解決,你的答覆是高度appriciated – user1346836

+0

Thnaks您寶貴的答覆 – user1346836

+0

@Braj爵士 - 漂亮的笑話,引用沒有太問題回答 –