如何使用Ksoap2,Android的消费会话相关的WCF服务 [英] How to consume Session dependent WCF services using Ksoap2-Android

查看:171
本文介绍了如何使用Ksoap2,Android的消费会话相关的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Ksoap2-的Andr​​oid 的消耗 WCF 服务。

对于 DOTNET客户端的我们保持 allowCookies =真正的在我们的绑定配置,并将其发送相同的SessionID,并保持我的会话保持不变在我的WCF服务(我的服务 相互依存和使用会话的)。

For the dotnet client we keep the allowCookies="true" in our binding configuration and it sends the same sessionid and keeps my sessions intact in my WCF services (My services are interdependent and use the sessions).

任何一个知道任何这样的设置 ksoap2-机器人,这将让我消耗 WCF服务让我的会议完好的服务器上。

Any one know any such setting for ksoap2-android, that will allow me to consume the WCF service keeping my session intact on the server.

目前,当我提出一个新的呼叫服务,在的SessionID 被改变,我所有的 会话变量清除,并失去其价值。

Currently when i make a new call to the service, the sessionid gets changed and all my session variables clear out and loose their values.

推荐答案

在C#我做的,只是使用了Android的方法来做到这一点,接下来的:

In C# i do the next, just use the android methods to do this:

1:使Http请求, 2:做第一个请求的Cookie的容器。 3.-把的CookieContainer在第二请求,例如你可以把捆绑在意图第二活动,并使用此cookie用于发送第二HTTP请求......

1.- Make the Http request, 2.- Make a Cookie Container of the first request. 3.- Put the cookieContainer over the second request, for example you can put in a bundle in a intent for the 2nd activity, and use this cookies for send the second http request...

我的C#code;

protected static void GetData()
    {
        CookieContainer cookies = new CookieContainer();
        HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("https://any.com/url");
        request1.CookieContainer = cookies;
        HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
        StreamReader responseReader1 = new StreamReader(response1.GetResponseStream());
        Response1 = responseReader1.ReadToEnd();
        responseReader1.Close();
        responseReader1.Dispose();

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
        request.CookieContainer = cookies;
        request.Method = "GET";
        request1.KeepAlive = true;
        try
        {
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader responseReader = new StreamReader(response.GetResponseStream());
            Response = responseReader.ReadToEnd();
            responseReader.Close();
            responseReader.Dispose();
            if (Response.Contains("Server Error in '/Verification' Application."))
            {
                Console.WriteLine("Empty Registry" + Url);
            }
        }
        catch (WebException ex)
        {
            if (ex.Response != null)
            {
                Console.WriteLine("Failed at: " + Url);
            }
            if (ex.Status == WebExceptionStatus.ProtocolError)
            {
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
                {
                    Console.WriteLine(ex.Status);
                }
            }
            else if (ex.Status == WebExceptionStatus.NameResolutionFailure)
            {
                Console.WriteLine(ex.Status);
            }

        }
    }

我这样做,为保持sesionID的第一个请求,后来,在第二个请求,我添加的CookieContainer(因为服务器需要我)(做一个机器人搜索);)...希望这个给你想法。

I do That for keep the sesionID of the first request, and later, in the second request, i add the cookieContainer (because the server requires me) (to make a bot search) ;)... hope this give you ideas.

这篇关于如何使用Ksoap2,Android的消费会话相关的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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