Using authentication

Nov 6, 2010 at 6:52 PM

Hello -

I am trying to use this library with a WP7 application. However, the service I am connecting to (an Azure Datamarket service) requires HTTP authentication. The documentation for that service says that I can create a NetworkCredential object and attach it to the container generated that inherits DataServiceContext, but when I tried this in my project, it does not appear that there is a "Credentials" property on the container class that was generated by the tool. Searching the source code for this library does not turn up the word "Credential" anywhere.

Is it the case this for a WP7 application, I will not be able to use HTTP authentication (and therefore, not be able to access Azure Datamarket from WP7), or am I just missing something here?

This is my first time working with all of these techs (WCF Data Services, Azure Datamarket, the OData library, etc.) so please forgive me if I'm missing something obvious...

Thanks!

J.Ja

Nov 9, 2010 at 6:04 AM

I am having the same problem. I want to write a client application for SharePoint on WP 7 using Odata Client libraries. Could not find a way to authenticate the user to SharePoint list data service. Can someone answer this please ?

Nov 10, 2010 at 6:55 PM

Apparently, the "solution" (according to a video on the Azure Datamarket site from PDC) is to construct the request URL manually in your application and use WebClient and provide it credentials, and parse the results yourself (most likely with LINQ to XML). Clumsy, and doesn't provide a strong, static typing like a lot of folks prefer.

J.Ja

Nov 12, 2010 at 10:50 AM
Edited Nov 12, 2010 at 10:50 AM

No, I actually found the solution and its pretty easy. Use the SendingRequest event (in DataServiceContext) to insert authentication cookie in the header.

Find the sample below :

               ClaimsWA501MIXEDWINFBADataContext context = new ClaimsWA501MIXEDWINFBADataContext(new Uri(@"http://duetlab2k8vm2:502/_vti_bin/listdata.svc"));
               context.SendingRequest += new EventHandler<SendingRequestEventArgs>(context_SendingRequest);

                employees = new DataServiceCollection<EmployeesItem>(context);
                employees.LoadAsync(customersUri);


                void context_SendingRequest(object sender, SendingRequestEventArgs e)
                {
                         e.RequestHeaders["Cookie"] = m_fbaCookie;
                }

Jan 27, 2011 at 6:46 AM

Hi, sumantbhardvaj.

 

Where did you set the value for the string variable "m_fbaCookie"?  Are you using a HttpOnly  cookie?

 

 

Guillermo