1

嗨,我有一个与 Android K-SOAP 相关的问题,我是第一次使用 K-SOAP Android

这是服务链接

在这里你可以看到请求,那里也提到了响应,这是我的代码来访问服务并获取响应`包 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”&lt;/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();
            }
        }
}`

请帮助我点击并从该服务中获得正确的响应非常感谢任何帮助

4

2 回答 2

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

它运行良好欢呼快乐编码

于 2012-06-22T14:17:41.070 回答
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();
                }

`

于 2012-06-22T11:27:06.710 回答