从的GetResponse SOAP Web服务在Android中 [英] GetResponse from SOAP webservices In Android

查看:204
本文介绍了从的GetResponse SOAP Web服务在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个SAP SOAP的Web服务的响应,但我得到一个例外。

I want get the response from a SAP SOAP Web service but I get an Exception.

我用下面的code:

package com.veee.pack;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import java.io.IOException;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportBasicAuth;
import org.ksoap2.transport.HttpTransportSE;
import org.w3c.dom.Element;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class WeservicesExampleActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //getting these values from wsdl file
       //username and password appended as URL Parameters
         final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
         final String URL = "http://*********:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user******&sap-password=************";
         final String METHOD_NAME = "Z_GET_CUST_GEN";
         final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";

        SoapObject request =new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("Input", "1460");
        request.addProperty("Langu", "d");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

        envelope.setOutputSoapObject(request);

        HttpTransportSE httptransport=new HttpTransportSE(URL);
        httptransport.debug = true;
        try {

          //calling the services
         httptransport.call(SOAP_ACTION, envelope);

         Object result = (Object) envelope.getResponse();

        //getting the Response Here.

         System.out.println("Result" + result.toString());

        }
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

当我调试它终止应用程序的

When I debug the Application it terminates at

httptransport.call(SOAP_ACTION, envelope); 

我跑了一些例子使用kso​​ap2 Android中它工作正常。我在我的logcat得到了以下异常:

I ran some examples by using ksoap2 in android it is working fine. I got the following exception in my logcat:

04-24 12:19:17.935: WARN/System.err(1569): java.net.SocketTimeoutException
04-24 12:19:17.935: WARN/System.err(1569):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:130)

请给出任何建议,以解决这个问题,或发送我怎样才能使请求和接收Android中通过XML响应。

Please give any suggestion to overcome this issue or send how can i make request and receive the response through XML in Android.

在此先感谢.....

Thanks in advance.....

推荐答案

使用SOAP在Android的..因为它是不建议回避。

AVoid using SOAP in android.. because it is not recommended.

使用宁静的web服务是officialy由机器人支载。 如果你的Web服务提供商无法提供RESTful服务,...承担着一些问题,如应用程序将无法正常工作一定时间,可能会在一些Android设备无法正常工作。

Use Restful webservices which is officialy suported by android. If your webservice provider is unable to provide Restful service,...bear with some problems like the app will not work some times and may not work in some of the android devices.

要摆脱问题与多个ksoap2驱动程序的ksoap2 impleentation戏,放在一个单独的线程的网络调用的逻辑。

To get rid of problems with your ksoap2 impleentation play with multiple ksoap2 drivers, put the logic of network calls in a separate thread.

要httptransport.call调用(SOAP_ACTION,包);消耗巨大的内存,更多的时间,从而避免使用此调用主线程。在尝试一个新的创建仿真器和设备之一。 KSOAP2工作20至50%的Andr​​oid设备。有些时候,它可能无法在设备从同一制造商的工作,例如,它可以工作在宏达感2.3.4,不得版本的HTC Sense 2.3.5工作。

The call to httptransport.call(SOAP_ACTION, envelope); consumes huge memory, more time and hence avoid using this call in main thread. Try in a new create emulator and one of the devices. KSOAP2 works 20 to 50% of android devices. Some times it may not work in a device from a same manufacturer, for example it may work in HTC sense 2.3.4 and may not work in ver 2.3.5 of HTC Sense.

建议将RESTful Web服务。

It is recommended to use Restful Webservices.

这篇关于从的GetResponse SOAP Web服务在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆