Ksoap2以https使用了大量的bandwitch如何优化连接? [英] Ksoap2 with https uses a lot of bandwitch How to optimize connections?

查看:522
本文介绍了Ksoap2以https使用了大量的bandwitch如何优化连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写使用kso​​ap2连接到HTTPS Web服务很多次的应用程序和应用程序的数据使用率很高。我认为这是很高的,因为我在做我每次调用WS时间的连接。

有就是用我的应用程序像一个单身或共享HttpTransportSE对象相同的连接方式?

我的code的一个例子:

 公共布尔Call1_Example(字符串参数1,字符串参数2)
{    SoapObject要求=新SoapObject空间(namespace,METHOD_NAME24);
    SoapSerializationEnvelope信封=新SoapSerializationEnvelope(
            SoapEnvelope.VER11);    request.addProperty(参数1参数1);
    request.addProperty(参数2,参数2);    envelope.dotNet = TRUE;
    envelope.setOutputSoapObject(请求);
    HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);    布尔resultado = FALSE;
    对象响应;    尝试{
        androidHttpTransport.call(Method1_SOAP_ACTION,
                信封);
        响应= envelope.getResponse();
        resultado = Boolean.parseBoolean(response.toString());    }赶上(例外五){        resultado = FALSE;
    }    返回resultado;
}


解决方案

我面临同样的问题。
我总是WS返回的整个对象我要求。
因此,我认为管理的每个服务器存储在每个setter方法​​使用System.currentTimeMillis的()对象的最后更新的时间。

当你消耗你的WS您检索响应,并保持最后更新的时间。
在接下来的请求WS,就会发送这个存储的时间。

因此​​,服务器会送你只是有一点不同。当然,它会导致你的服务器的code的修改。

我不知道这是否是一个干净的解决方案,但它工作正常。我已经得到了近似相同的时间响应WiFi和3G中的

您也可以使用gzip COM preSS的消息。

  HeaderProperty headerProperty =新HeaderProperty(接受编码,gzip的);

您可以看到一个样本<一个href=\"http://stackoverflow.com/questions/14624136/how-to-request-a-gzipped-com$p$pssed-soap-response\">here

I'm writing an app that connect to an https web service many times using ksoap2 and the data usage of the app is high. I think it's high because I'm doing the connection every time i invoke the WS.

There is a way to use the same connection for my application like a singleton or sharing the HttpTransportSE object?

An example of my code:

public boolean Call1_Example(String Param1, String Param2)
{

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME24);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);

    request.addProperty("Param1", Param1);
    request.addProperty("Param2", Param2);

    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    Boolean resultado = false;
    Object response;

    try {


        androidHttpTransport.call(Method1_SOAP_ACTION,
                envelope);
        response = envelope.getResponse();
        resultado = Boolean.parseBoolean(response.toString());

    } catch (Exception e) {

        resultado = false;
    }

    return resultado;
}

解决方案

I faced the same problem. My WS always returned the whole object I requested. So I manage that the server stores for each object its last updated time by using System.currentTimeMillis() in every setters.

When you consume your WS you retrieve the response and keep the last updated time. For the next request to the WS, you'll send this stored time.

So the server will send you only the difference. Of course, it leads to a modification of your server's code.

I don't know if it's a clean solution, but it works fine. I've got approximatively the same time response in Wifi and in 3G.

You can also use gzip to compress the message.

HeaderProperty headerProperty=new HeaderProperty("Accept-Encoding", "gzip");

You can see a sample here

这篇关于Ksoap2以https使用了大量的bandwitch如何优化连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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