IT tutorials
 
Technology
 

Sharepoint 2010 : Writing Custom WCF Services (part 3) - Consuming the Service in a Silverlight application

8/28/2013 3:02:15 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Consuming the Service in a Silverlight application

In your CustomWCFService SharePoint project, add a Silverlight application called SLLists. When prompted to host the Silverlight application in a new web site, choose to not create that web site. As a mentioned earlier, WCF allows you to swap both the front end and back end as long as the contract remains the same. Thus sometimes it is helpful to add this external web application, not debug in SharePoint, and send dummy objects. These dummy objects can then be used for TDD purposes or to build UI inside Expression Blend or such!

Back in your Silverlight application, choose to add a service reference. When prompted, click the Discover button to add the service reference being generated directly from MyServiceLibrary. You can also use a utility called SLSVCUtil.exe to generate proxies and add them manually to your Silverlight project. Just like the console application, in order to generate a ServiceReference in Silverlight, the service needs to publish metadata. Because the SharePoint service is not publishing metadata, we can choose to generate the service proxy from MyServiceLibrary instead. However before you can successfully generate such a ServiceReference in Silverlight, you need to edit the app.config file of your MyServicelibrary to use basicHttpBinding instead of wsHttpBinding. To do this, look for the following line of code in the App.config of MyServiceLibrary:

<endpoint address="" binding="wsHttpBinding" contract="MyServiceLibrary.IListsService">


Change it to this:

<endpoint address="" binding="basicHttpBinding" contract="MyServiceLibrary.IListsService">


You have to make this change because Silverlight can talk only to basicHttpBinding endpoints or REST -based APIs. Call the proxy ServiceReference1.

With the ServiceReference added, now you can start writing some Silverlight Code. Go ahead and edit the MainPage.xaml file to look like Listing 6.

Example 6. Code for MainPage.xaml
<Grid x:Name="LayoutRoot" Background="White">
<ListBox x:Name="lists">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" Margin="10 0 10 0"/>
<TextBlock Text="{Binding Path=Author}" Margin="10 0 10 0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>

I've declared a simple listbox, in which I intend to databind my custom business object. Back in MainPage.xaml.cs, add the code shown in Listing 7.

Example 7. Code for MainPage.xaml.cs
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ServiceReference1.ListsServiceClient client = new ServiceReference1.ListsServiceClient(
new BasicHttpBinding(),
new EndpointAddress("http://sp2010/_vti_bin/CustomWCFService/listservice.svc"));

client.GetListsCompleted += (sender1, e1) =>
{
lists.ItemsSource = e1.Result;
};

client.GetListsAsync();
}


The code is quite similar to what you have seen before. I'm making an asynchronous called to the WCF endpoint and data binding the results to the list box I had declared in Listing 6. You would also note that for simplicity I hardcoded the endpoint address.

Deploy the XAP output of SLlists as a module in the custom WCF service SharePoint project. Build and deploy the solution and use the out-of-the-box Silverlight viewer WebPart in SharePoint to view the Silverlight application running inside SharePoint. You should see the lists and the author of the lists retrieved, as shown in Figure 6.

Figure 6. WCF service results being shown in a Silverlight UI
 
Others
 
- Sharepoint 2010 : Writing Custom WCF Services (part 2) - Consuming the Service in a .NET Application
- Sharepoint 2010 : Writing Custom WCF Services (part 1)
- Active Directory 2008 : Configuring Password and Lockout Policies (part 2) - Fine-Grained Password and Lockout Policy
- Active Directory 2008 : Configuring Password and Lockout Policies (part 1) - Understanding Password Policies , Understanding Account Lockout Policies
- Active Directory 2008 : Implementing a Group Policy Infrastructure - Supporting Group Policy (part 2)
- Active Directory 2008 : Implementing a Group Policy Infrastructure - Supporting Group Policy (part 1)
- Microsoft Lync Server 2010 : Enterprise Voice - Call Admission Control (part 2) - Network Region Links, Network Region Routes
- Microsoft Lync Server 2010 : Enterprise Voice - Call Admission Control (part 1) - Bandwidth Policy Profiles , Associate Bandwidth Policy Profile
- Microsoft Lync Server 2010 : Enterprise Voice - Network Configuration - Network Regions, Network Sites, Network Subnets
- Microsoft Lync Server 2010 : Enterprise Voice - Voice Features - Call Park, Unassigned Numbers
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us