Implementing session in SOAP Client

后端 未结 1 1698
萌比男神i
萌比男神i 2021-01-28 14:09

I am developing a WP application for which the webservices are implemented in .NET using SOAP client. I have implemented the SOAP client in my WP app using \"Add service referen

相关标签:
1条回答
  • 2021-01-28 14:39

    Finally I figured out how to maintain cookie based session in Windows phone apps

    Thanks to Mike for his guidance.

    For all those who are wondering about the different ways of maintaining session in WP app, there is a class called CookieContainer which helps to maintain cookie data for us.

    Usage:

    First create a global instance of CookieContainer class ( I created in App.xaml.cs)

    //In App.xaml.cs
    CookieContainer cookieContainer = new CookieContainer();
    

    And then assign it to every request we make to the server from our app.

    MySoapClient client = new MySoapClient();
    client.CookieContainer = (App.Current as App).cookieContainer;
    client.LoginAsync("username", "password");
    

    Again for any other request in the app

    MyOtherSoapClient anotherClient = new MyOtherSoapClient();
    anotherClient.CookieContainer = (App.Current as App).cookieContainer;
    anotherClient.PostDataAsync("somedata");
    

    The same rule also applies for normal WebClient and HttpWebRequest classes also.

    Happy Coding :)

    0 讨论(0)
提交回复
热议问题