如何使用SOAP服务机器人如何使用、机器人、SOAP

2023-09-07 13:37:56 作者:封心锁爱只为等一人

我是新来的Andr​​oid。任何人都可以请帮我开始使用SOAP服务有任何例子或源$ C ​​$ C的帮助?在此先感谢

I am new to Android. Can anyone please help me to get started with Soap services with the help of Any example or source code ? Thanks in advance

推荐答案

如果您的web服务基于.NET使用此方法:

use this method if your webservice is .Net based:

private static SoapObject callWebServiceMethod(String url,
        String namespace, String methodName,
        HashMap<String, Object> parameters, String soapAction)
        throws Exception {

    Log.i("WebService", "URL: " + url);
    Log.i("WebService", "MethodName: " + methodName);

    URL myurl = new URL(url);
    URLConnection connection = myurl.openConnection();
    connection.setConnectTimeout(20 * 1000);
    HttpURLConnection httpConnection = (HttpURLConnection) connection;
    int responseCode = httpConnection.getResponseCode();
    if (responseCode == HttpURLConnection.HTTP_OK)
    {
        httpConnection.disconnect();
        SoapObject request = new SoapObject(namespace, methodName);

        if (parameters != null) {
            String[] keys = new String[0];
            keys = (String[]) parameters.keySet().toArray(keys);
            Object[] vals = (Object[]) parameters.values().toArray();

            for (int i = 0; i < parameters.size(); i++) {
                request.addProperty(keys[i], vals[i]);
                Log.i("WebService", keys[i] + ": " + vals[i]);
            }
        }

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(url,
                TimeOutInSeconds * 1000);


        androidHttpTransport.call(soapAction, envelope);


        SoapObject so = (SoapObject) envelope.getResponse();

        return so;

    }
    else
    {
        httpConnection.disconnect();

    }

}

下载KSOAP库使用这个链接