DataServiceContext consume ODATA Service & Authentication RRS feed

  • Question

  • I have a Lightswitch developer ODATA services, the Silverlight client runs good,the web config:

    <authentication mode="Forms">

    Now I am using WPF to develop a new client, the DataServiceContext object can consume ODATA services. CODE :

    ApplicationData dataSvc


     dataSvc = new ApplicationData(
        new Uri("http://ip.../Test/ApplicationData.svc/"));
    dataSvc.Credentials = new NetworkCredential("username", "pwd");


    var query = from a in dataSvc.ProjectDocuments select a;
    var  query1 = from  b in dataSvc.ProjectItemSet select b;

    I can use the dataservicecontext object to automatically log on and get ODATA data.

    But I found that there were two problems. Use the Fiddler tool, I found a second calling, there were 4 HTTP requests. Each time it is called, the first request will be rejected by the server, and displays a 401 error, the second request is can I get the expected data.
    By SQL Server Profiler to monitor, I found that each time it is called service again in the database again using the MemberShip to authenticate users.

    I'm feeling the DataServiceContext object as if not for session state management, every call will initiate a session again.

    How to deal with this phenomenon, and what needs to be done to modify.

       void dataSvc_SendingRequest2(object sender, SendingRequest2EventArgs e)
                if (cookie != null)
                    e.RequestMessage.SetHeader("Cookie", cookie);
            string cookie = null;
            void dataSvc_ReceivingResponse(object sender, ReceivingResponseEventArgs e)
                if (cookie == null)
                    cookie = e.ResponseMessage.GetHeader("Set-Cookie");

    I manually set the COOKIE, but nothing has changed

    Wednesday, July 29, 2015 5:22 AM

All replies