在 Android 中使用没有 ksoap2 的 SOAP Web 服务

发布于 2024-11-19 23:46:10 字数 146 浏览 9 评论 0原文

在我的Android应用程序中,我使用kso​​ap2库来使用soap(& .net)网络服务。它工作正常,但速度非常慢(对于解析、控制、循环和 Base64ToBinary 进程)。我想更快地解析它。不使用kso​​ap2是否可以解析它?有什么想法吗? 感谢您的建议。

In my Android application, i'm using ksoap2 library for consuming a soap ( & .net) webservice. It works correctly but it's very slow (for parsing, controls, loops and Base64ToBinary processes). I want to parse it more fast. Is it possible to parse it without using ksoap2? Any ideas?
Thanks for your recommendations.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开柳相依 2024-11-26 23:46:11

你说慢是什么意思?它执行 http 请求,然后解析响应。您必须在异步任务中执行此操作。内存使用情况将取决于您收到的响应。也许你的要求太多了。请参阅 wiki 了解如何调试!

What do you mean slow? It does a http request and then parses the response. You have to do this in an async task. Memory usage will depend on the response you get. Maybe you are requesting way too much. See the wiki on how to debug!

丑丑阿 2024-11-26 23:46:11

我对 KSoap2 还有另一个问题。不幸的是,ksoap2 库无法与我的网络服务一起使用。最后,我完成了默认的 http post。

我希望这对将来的人有帮助。

private String makeHttpRequest(){
        try{
            String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://tempuri.org/\">"
                    +"<SOAP-ENV:Body>"
                    + "<ns1:Connect>"
                    + "<ns1:lstr_Login>xxxxx</ns1:lstr_Login>"
                    +"</ns1:Connect>"
                    +"</SOAP-ENV:Body>"
                    +"</SOAP-ENV:Envelope>";

            String soapAction = "http://tempuri.org/Connect"; //this would be your soapAction from wsdl

            StringEntity se = new StringEntity(request, HTTP.UTF_8);
            DefaultHttpClient client = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(new URI("http://xxxxxxxx.com/Storefront.asmx"));

            httpPost.addHeader("Content-Type", "text/xml; charset=utf-8");
            httpPost.addHeader("SOAPAction", soapAction);

            httpPost.setEntity(se);
            HttpResponse response = client.execute(httpPost);
            int responseStatusCode = response.getStatusLine().getStatusCode();
            Log.d(TAG, "HTTP Status code:"+responseStatusCode);
            if(responseStatusCode>=200 && responseStatusCode<300){
                //we got the success response from server. Now retrieve the value and go for usage.
                String responseStr = EntityUtils.toString(response.getEntity());
                //use this responseStr to parse with pullparsers or any
                Log.d("Response", "Response:: "+ responseStr);
                return responseStr;
            }
        }catch(Exception e){
            //Write the proper catch blocks for exceptions
            Log.e("Response Exception" , e.getMessage()+"",e);
        }
        return null;
    }

I have another problem with KSoap2. Unfortunately, ksoap2 library is not working with my webservices. So at last, I have done with default http post.

I hope this will help for someone in future.

private String makeHttpRequest(){
        try{
            String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://tempuri.org/\">"
                    +"<SOAP-ENV:Body>"
                    + "<ns1:Connect>"
                    + "<ns1:lstr_Login>xxxxx</ns1:lstr_Login>"
                    +"</ns1:Connect>"
                    +"</SOAP-ENV:Body>"
                    +"</SOAP-ENV:Envelope>";

            String soapAction = "http://tempuri.org/Connect"; //this would be your soapAction from wsdl

            StringEntity se = new StringEntity(request, HTTP.UTF_8);
            DefaultHttpClient client = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(new URI("http://xxxxxxxx.com/Storefront.asmx"));

            httpPost.addHeader("Content-Type", "text/xml; charset=utf-8");
            httpPost.addHeader("SOAPAction", soapAction);

            httpPost.setEntity(se);
            HttpResponse response = client.execute(httpPost);
            int responseStatusCode = response.getStatusLine().getStatusCode();
            Log.d(TAG, "HTTP Status code:"+responseStatusCode);
            if(responseStatusCode>=200 && responseStatusCode<300){
                //we got the success response from server. Now retrieve the value and go for usage.
                String responseStr = EntityUtils.toString(response.getEntity());
                //use this responseStr to parse with pullparsers or any
                Log.d("Response", "Response:: "+ responseStr);
                return responseStr;
            }
        }catch(Exception e){
            //Write the proper catch blocks for exceptions
            Log.e("Response Exception" , e.getMessage()+"",e);
        }
        return null;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文