i have a list in my sharepoint site. now i want to retrieve the data from that List and pass it to silverlight application. for that i want to using Sharepoint WebServices( List.asmx).
Can anyone tell me how to use sharepoint web services in silverlight application.
For taking data from sharepoint list you have to follow below steps
1)Take service reffernce of your list.asmx
2)Paste the crossdomainplicy file at root folder of your sharepoint website.
3)Configure u r IIS MIME Type as .xap & application/x-silverlight-app xap.
4)then craete the object of your websevice client ie.ListSoapClient.Create
GetListItemsCompleted handeler.Then call GetListItemsAsync("ListName",
null, null,
null, null,
null, string.Empty).
Code for calling webservice & collecting data in list format.Where
Barrier is class which contain propetries related to your list columns.
public
List<Barrier> BarrierData;
public Page()
{
InitializeComponent();
BarrierDataService.ListsSoapClient web =
new eSENSE_BarChart.BarrierDataService.ListsSoapClient();
web.GetListItemsCompleted +=
new
EventHandler<eSENSE_BarChart.BarrierDataService.GetListItemsCompletedEventArgs>(web_GetListItemsCompleted);
web.GetListItemsAsync("My Barriers",
null, null,
null, null,
null, string.Empty);
XDocument lobjDocument =
XDocument.Parse(e.Result.ToString());
XNamespace lobjNamespace =
"#RowsetSchema";
var Result = from view1
in lobjDocument.Descendants(lobjNamespace +
"row")
select new
Barrier
{
NoIncident = (
Double)view1.Attribute("ows_No_x002e__x0020_of_x0020_Inciden"),<---- Intenal sharepoint name for your list column
BarrierTagNo = (string)view1.Attribute("ows_Barrier_x0020_Tag_x0020_No_x002e"),<---- Intenal sharepoint name for your list column
thank u. but can u plz explain me this part of code?
XDocument lobjDocument = XDocument.Parse(e.Result.ToString());
XNamespace lobjNamespace =
"#RowsetSchema";
var Result = from view1
in lobjDocument.Descendants(lobjNamespace +
"row")
select new
Barrier
{
NoIncident = (
Double)view1.Attribute("ows_No_x002e__x0020_of_x0020_Inciden"),<---- Intenal sharepoint name for your list column
BarrierTagNo = (string)view1.Attribute("ows_Barrier_x0020_Tag_x0020_No_x002e"),<---- Intenal sharepoint name for your list column
As data comes in xml format from list.asmx ,we have to convert that xml data in ti list format.That all code is LINQ code for retriving data from xml in to List of type Barrier.where Barrier is my property class ie. in your case your barrier class will as
follow
public class Barrier
{
string _Title=string.Empty;
string _Body=string.Empty;
DateTime _ExpiryDate=null;
DateTime _DisplayDate=null;
public string Title
{
get
{
return
this.__Title;
}
set
{
this.__Title=
value;
}
}
public string Body
{
get
{
return
this.__Body;
}
set
{
this.__Body=
value;
}
}
public DateTime ExpiryDate
{
get
{
return
this.__ExpiryDate;
}
set
{
this.__ExpiryDate=
value;
}
}
public DateTime DisplayDate
{
get
{
return
this.__DisplayDate;
}
set
{
this.__DisplayDate=
value;
}
}
}
after in completed event handler
XDocument lobjDocument =
XDocument.Parse(e.Result.ToString());<------ This staement parse u r xml in to XDocument
XNamespace lobjNamespace =
"#RowsetSchema";<--- This is your xml namespace in u r xml returned by webservice
where below staement is your Linq query which retrives data from u r xml.
var Result = from view1
in lobjDocument.Descendants(lobjNamespace +
"row")
select new
Barrier
{
Title= (string)view1.Attribute("ows_Title"),<--- internal name for sharepoint list colmn
Hema123
Member
14 Points
116 Posts
Using webservices in Silverlight Control
Nov 24, 2008 09:25 AM | LINK
Hi,
i have a list in my sharepoint site. now i want to retrieve the data from that List and pass it to silverlight application. for that i want to using Sharepoint WebServices( List.asmx).
Can anyone tell me how to use sharepoint web services in silverlight application.
davidezordan
Contributor
6294 Points
957 Posts
Re: Using webservices in Silverlight Control
Nov 24, 2008 12:00 PM | LINK
Hi,
here http://silverlight.net/forums/p/26453/91694.aspx you can find more information.
Have a nice day,
Silverlight MVP
Blog Twitter Silverlight Experts
Hema123
Member
14 Points
116 Posts
Re: Re: Using webservices in Silverlight Control
Nov 25, 2008 05:49 AM | LINK
"GetListItemsCompleted" is not fired in that code
spiderman110
Member
226 Points
290 Posts
Re: Re: Re: Using webservices in Silverlight Control
Nov 25, 2008 07:15 AM | LINK
Hi,Hema123
First, you should create your web service method.
Update your web service and then you could get the event of it.
hiteshbhagwat
Participant
1291 Points
294 Posts
Re: Using webservices in Silverlight Control
Nov 25, 2008 08:37 AM | LINK
Hi,
For taking data from sharepoint list you have to follow below steps
1)Take service reffernce of your list.asmx
Code for calling webservice & collecting data in list format.Where Barrier is class which contain propetries related to your list columns.2)Paste the crossdomainplicy file at root folder of your sharepoint website.
3)Configure u r IIS MIME Type as .xap & application/x-silverlight-app xap.
4)then craete the object of your websevice client ie.ListSoapClient.Create GetListItemsCompleted handeler.Then call GetListItemsAsync("ListName", null, null, null, null, null, string.Empty).
public
List<Barrier> BarrierData; public Page(){
InitializeComponent();
BarrierDataService.ListsSoapClient web = new eSENSE_BarChart.BarrierDataService.ListsSoapClient();web.GetListItemsCompleted +=
new EventHandler<eSENSE_BarChart.BarrierDataService.GetListItemsCompletedEventArgs>(web_GetListItemsCompleted); web.GetListItemsAsync("My Barriers", null, null, null, null, null, string.Empty);}
void web_GetListItemsCompleted(object sender, eSENSE_BarChart.BarrierDataService.GetListItemsCompletedEventArgs e){
XDocument lobjDocument = XDocument.Parse(e.Result.ToString()); XNamespace lobjNamespace = "#RowsetSchema"; var Result = from view1 in lobjDocument.Descendants(lobjNamespace + "row") select new Barrier{
Double)view1.Attribute("ows_No_x002e__x0020_of_x0020_Inciden"),<---- Intenal sharepoint name for your list column BarrierTagNo = (string)view1.Attribute("ows_Barrier_x0020_Tag_x0020_No_x002e"),<---- Intenal sharepoint name for your list column};
BarrierData = Result.ToList<
Barrier>();}
Hitesh
If this answer your que plz mark as answer
Hema123
Member
14 Points
116 Posts
Re: Re: Using webservices in Silverlight Control
Nov 25, 2008 10:54 AM | LINK
Can u explain me about 2nd step. from where could i get the file?
spiderman110
Member
226 Points
290 Posts
Re: Re: Re: Using webservices in Silverlight Control
Nov 25, 2008 10:57 AM | LINK
Well, I can paste it here.The file is named clientaccesspolicy.xml.
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Hema123
Member
14 Points
116 Posts
Re: Re: Re: Re: Using webservices in Silverlight Control
Nov 25, 2008 11:42 AM | LINK
thank u. but can u plz explain me this part of code?
XDocument lobjDocument = XDocument.Parse(e.Result.ToString()); XNamespace lobjNamespace = "#RowsetSchema"; var Result = from view1 in lobjDocument.Descendants(lobjNamespace + "row") select new Barrier{
Double)view1.Attribute("ows_No_x002e__x0020_of_x0020_Inciden"),<---- Intenal sharepoint name for your list column BarrierTagNo = (string)view1.Attribute("ows_Barrier_x0020_Tag_x0020_No_x002e"),<---- Intenal sharepoint name for your list column};
BarrierData = Result.ToList<
Barrier>();Hema123
Member
14 Points
116 Posts
Re: Re: Re: Re: Re: Using webservices in Silverlight Control
Nov 25, 2008 12:24 PM | LINK
Hi,
I have created a list in my sharepoint site. it consists of 4 columns.
Title,Body,ExpiryDate,DisplayDate
I am passing the ListName , ViewName to Silverlight application.
By using GetListItemsAsync() and GetListItemsCompleted how can i retrieve the data from that list.
hiteshbhagwat
Participant
1291 Points
294 Posts
Re: Re: Re: Re: Re: Using webservices in Silverlight Control
Nov 26, 2008 03:30 AM | LINK
As data comes in xml format from list.asmx ,we have to convert that xml data in ti list format.That all code is LINQ code for retriving data from xml in to List of type Barrier.where Barrier is my property class ie. in your case your barrier class will as follow
public class Barrier
{
string _Title=string.Empty;
string _Body=string.Empty;
DateTime _ExpiryDate=null;
DateTime _DisplayDate=null;
public string Title
{
get
{
return this.__Title;
}
set
{
this.__Title= value;
}
}
public string Body
{
get
{
return this.__Body;
}
set
{
this.__Body= value;
}
}
public DateTime ExpiryDate
{
get
{
return this.__ExpiryDate;
}
set
{
this.__ExpiryDate= value;
}
}
public DateTime DisplayDate
{
get
{
return this.__DisplayDate;
}
set
{
this.__DisplayDate= value;
}
}
}
after in completed event handler
XDocument lobjDocument = XDocument.Parse(e.Result.ToString());<------ This staement parse u r xml in to XDocument XNamespace lobjNamespace = "#RowsetSchema";<--- This is your xml namespace in u r xml returned by webservicewhere below staement is your Linq query which retrives data from u r xml.
var Result = from view1 in lobjDocument.Descendants(lobjNamespace + "row") select new Barrier{
Title= (string)view1.Attribute("ows_Title"),<--- internal name for sharepoint list colmnBody= (
string)view1.Attribute("ows_Body") ExpiryDate= (DateTime )view1.Attribute("ows_ExpiryDate"),DisplayDate= (
DateTime )view1.Attribute("ows_DisplayDate")};
convert this var in to list of type barrier.
If you want see the internal name of your sharepoint list column place breakpoint in completed event handler & check the value of lobjDocument.
Hitesh
If this answer your que plz mark as answer