Writing Windows Phone Apps for SharePoint
Writing a blog post after quite some time. (Well frankly was thinking on what sort of post to write)
We have heard / seen / read about how windows phone has good SharePoint 2010 integration features as to how the office hub can integrate with your corporate intranet SharePoint site and how, you can leverage the SharePoint workspace capabilities in windows phone.
after reading about this, you’d say cool, can i write an app which speaks to my SharePoint site. Well the answer is Yes. But there are some changes that you need to to do on SharePoint site configuration.
“Argh!!, making changes on SharePoint site, My boss(and/or system admin) will kill me! “.
Was this your reaction ? (at least, that was my initial reaction).
In that case, this post might not be of that much help.
However, we can always host a cloud service that would help you get data from SharePoint and you can consume the data from this “middle man” cloud service. ( Off course this does add up expenses that at the end of the day needs to be taken care off by some one)
So, why is that I cannot consume SharePoint service directly from my windows phone.
Well it all began, when windows phone SDK team decided to omit NTLM auth support from the SDK, thus preventing us 3rd party developers from directly writing cool apps that speak to your SharePoint site.
“Why did they do this to us? “ you ask!!, Well frankly, i don’t have an answer to that.
But, There is a way out of this. How is that? Well , all you got to do is enable Forms based authentication for your SharePoint site.
How do I do that? There is a good article here. (Remember, you need to be very very strong hearted to take up all these changes, as these changes might literally take down your SharePoint site. )
Here’s a pictorial representation of auth mechanisms and SharePoint support for the same.
(Stolen from Paul Stubbs blog on MSDN, Sorry!! )
Well what story, the above diagram is trying to tell is:
SharePoint 2010 supports two different authentication modes.
1. Classic mode (The Loner left side branch, support NTLM authentication only)
2. Claims based mode (The right side branch of the diagram above)
What you can realise is that if you use the claims based mode for creating your SharePoint web application, you can use any of the claims providers to authenticate yourself (in this case, your phone app’s code) to your SharePoint site. (Off course, your system administrator can have hard time configuring the same, but lets not get into that )
Once you have the infrastructure in place. All you got to do is use the SharePoint 2010 Web services to access SharePoint lists etc.
In SharePoint, you cannot make any changes to a spsite until you are an authenticated user. So You need to log in programmatically to make changes such as adding list items, modifying ‘em etc.
For Logging in , you can use the authentication.asmx web service to authenticate yourself.
(the spsite you are trying to access via your code needs to allow
form based authentication.) The Authentication site is available at : http://[YourSiteName]/_vti_bin/authentication.asmx
Logging into SharePoint
Here’s what happens when you visit a SharePoint site: (Again stolen for Paul stubbs’ blog , sorry again!!)
1. you visit a SharePoint site page.
2. you are redirected to the login page(this internally uses the authentication web service), you enter your credentials here.
3. the authentication service returns a security token(FEDAUTH).
4. this security token is passed for all subsequent calls to the SharePoint site.
5. this security token is verified by the server for validity and then the server returns the requested resource.
How Do I do this Programatically?
Well, for programmatically mimicking the above mentioned behaviour, you can write code that looks something like this: