Accessing web service in SharePoint Online (Cloud –Office 365).
It was an end of a tiring day where I tried to consume a web service in the SharePoint online and finally I succeeded. Thanks to Sajid Mohammad who redirected me to the blog of Wictor , and a great thanks to him for providing MsOnlineClaimsHelper class.Un like in Wictor’s example my requirement was to consume a web service.
So All need to do is that assign my webservice’s cookicontainer class to the claims helper’s cookiecontainer as follows.
objLists.CookieContainer = claimsHelper.CookieContainer;
The whole code will look like below.
try
{
MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper("http://......./teamsite/_vti_bin/Lists.asmx", @"<username>", "<password>");
FileGET.Lists objLists = new FileGET.Lists();
objLists.CookieContainer = claimsHelper.CookieContainer;
objLists.Url = "http://dev22.sharepoint.com/TeamSite/_vti_bin/Lists.asmx";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
XmlNode ndListItems = objLists.GetListItems("test", null, null, null, null, ndQueryOptions, null);
XmlTextReader reader = new XmlTextReader(ndListItems.OuterXml, XmlNodeType.Element, null);
//to display in my windows application
DataSet ds = new DataSet();
ds.ReadXml(reader);
dataGridView1.DataSource = ds.Tables[1];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
----------------------------------------------------------------------------------------------------------------------------
Note : In case you are calling this with in a firewall dont forget to put the following ahead of the script.
if (WebRequest.DefaultWebProxy.Credentials == null)WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
It is very useful.
ReplyDeleteThanks,
Nattuthurai kuppusamy
From where can I get the class named MsOnlineClaimsHelper.cs
ReplyDeleteI got it from here
Deletehttp://community.office365.com/en-us/forums/154/t/64976.aspx
Hi,
ReplyDeleteI am trying to use MsOnlineClaimsHelper in a SandBoxed solution, but It not works. I think because sercurity issues
I need to display a list in a "public-facing Website" from my internal site.
Do you have some tip for me?
Did you try the "Note:" I mentioned, Firewall will be the culprit
Delete