Introduction
In this article let's concentrate on another Silverlight application, whereby communicating with a WCF Service to perform some operation.
The Telerik Rad Controls for Silverlight can be found from http://www.telerik.com/products/silverlight/controls.aspx.
The Rad Window is used to display the output in a nice and enhanced UI.
Question: What is RadBarCode?
In simple terms "It provides light weighted and easy systematic approach to generate bar-codes, it used to ensure unique id given to each product when evaluating".
Let's get this implemented practically for a better idea of this!!!
Step 1: The complete code of the IService1.cs looks like this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace Wcf_Rad_Bar
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
int bar(int a);
}
}
Step 2: The complete code of the Service1.svc.cs looks like this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace Wcf_Rad_Bar
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public int bar(int a)
{
return a;
}
}
}
Step 3 : The complete code of the Web.Config looks like this.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Step 4 : The complete code of the Clientaccesspolicy.xml looks like this (to avoid cross domain problem in Silverlight).
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Step 5 : The complete code of the MainPage.xaml looks like this.
<UserControl x:Class="Rad_Bar_App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot" Width="628" Height="452">
<telerik:RadBarcode128 Name="radBar1"
ShowChecksum="False"
Margin="104,0,113,189"
Height="89"
VerticalAlignment="Bottom">
</telerik:RadBarcode128>
<TextBlock Height="23"
HorizontalAlignment="Left"
Margin="191,12,0,0"
Name="textBlock1" Text="Please Enter Bar Code Number"
FontFamily="Verdana"
FontSize="15"
VerticalAlignment="Top" />
<TextBox Height="23"
HorizontalAlignment="Left"
Margin="248,41,0,0"
Name="textBox1"
VerticalAlignment="Top"
Width="120" />
<Button Content="Send BarCode"
FontFamily="Verdana"
Background="DeepSkyBlue"
FontSize="15"
Height="23"
HorizontalAlignment="Left"
Margin="235,82,0,0"
Name="button1"
VerticalAlignment="Top"
Width="133"
Click="button1_Click"/>
<telerik:RadBarcode93 Name="radBar93"
Margin="104,336,113,22" ShowChecksum="False">
</telerik:RadBarcode93>
<TextBlock Height="23"
HorizontalAlignment="Left"
Margin="235,289,0,0"
Name="textBlock2"
Text="RadBarCode93"
FontFamily="Verdana"
FontSize="15"
VerticalAlignment="Top"
Width="170"
FontWeight="Bold"
Visibility="Collapsed"
/>
<TextBlock Height="23"
HorizontalAlignment="Left"
Margin="234,129,0,0"
Name="textBlock3"
Text="RadBarCode128"
FontFamily="Verdana"
FontSize="15"
FontWeight="Bold"
VerticalAlignment="Top"
Width="134"
Visibility="Collapsed"/>
</Grid>
</UserControl>
Step 6 : The complete code of the MainPage.xaml.cs looks like this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Rad_Bar_App.ServiceReference1;
namespace Rad_Bar_App
{ public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void bar_Call(object sender, barCompletedEventArgs e)
{
radBar1.Visibility = System.Windows.Visibility.Visible;
radBar93.Visibility = System.Windows.Visibility.Visible;
radBar1.Text = e.Result.ToString();
radBar93.Text = e.Result.ToString();
textBlock2.Visibility = System.Windows.Visibility.Visible;
textBlock3.Visibility = System.Windows.Visibility.Visible;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
textBlock2.Visibility = System.Windows.Visibility.Collapsed;
textBlock3.Visibility = System.Windows.Visibility.Collapsed;
radBar1.Visibility = System.Windows.Visibility.Collapsed;
radBar93.Visibility = System.Windows.Visibility.Collapsed;
if (string.IsNullOrEmpty(textBox1.Text))
{
RadWindow.Alert("Please Enter Some Values");
}
else
{
Service1Client obj_Client = new Service1Client();
obj_Client.barCompleted += new EventHandler<barCompletedEventArgs>(bar_Call);
obj_Client.barAsync(Convert.ToInt32(textBox1.Text));
textBox1.Text = "";
}
}
}
}
Step 7 : The output of the application looks like this.
Step 8 : The output of the Nothing Entered Application looks like this.
Step 9 : The output of the BarCodeEntered Application looks like this.
I hope this article is useful for you ...I look forward to your comments and feedback....Thanks.