Step1 : Create a Database Called: SilverData
Step2: Execute following code in SQL
USE [SilverData]GO/****** Object: Table [dbo].[Silver] Script Date: 01/02/2012 18:08:16 ******/SET
GO
SET
GO
SET
GO
CREATE ANSI_NULLS ON QUOTED_IDENTIFIER ON ANSI_PADDING ON TABLE [dbo].[Silver]([Name] [varchar](50) NULL,[Address] [varchar](50) NULL,[Id] [int]
)IDENTITY(1,1) NOT NULL ON [PRIMARY]GO
SET
GO
Step3: Create a Silverlight project(Silverlight Application -SampleSilverlight)
It ll create the project Samplsilverlight.web,
Step4: In Samplesilverlight.web project-add a WCF Service(SampleSilver.svc)
Step5: In SampleSilver.svc.cs- Paste following code
[ServiceContract]
public class SampleSilver
{
SqlConnection Conn;
SqlCommand Cmd;
public SampleSilver()
{
}
//Below will help to Insert New records from DataForm :
[OperationContract]
public bool InsertEmployee(string Name,string Address)
{
bool Inserted = false;
Conn = new SqlConnection(@"Data Source=sp4\SQLEXPRESS;Initial Catalog=SilverData;Integrated Security=true");
Cmd = new SqlCommand();
Conn.Open();
Cmd.Connection = Conn;
Cmd.CommandText = "Insert into Silver Values (@Name,@Address)";
Cmd.Parameters.AddWithValue("@Name", Name);
Cmd.Parameters.AddWithValue("@Address", Address);
int ins = Cmd.ExecuteNonQuery();
if (ins > 0)
{
Inserted = true;
}
Conn.Close();
return Inserted;
}
public void DoWork()
{
}
Step6: Design Your Page(MainPage.xaml)
<Grid x:Name="LayoutRoot" Width="690" Height="490" ShowGridLines="True" Background="Gainsboro">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="345"></ColumnDefinition>
<ColumnDefinition Width="345"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="21,20,0,0" Name="textBlock1" Text="Name" VerticalAlignment="Top" Width="78" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="21,49,0,0" Name="textBlock2" Text="Address" VerticalAlignment="Top" Width="148" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="135,20,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="135,49,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="101,0,0,359" Name="button1" VerticalAlignment="Bottom" Width="97" Click="button1_Click" />
</Grid>
Step7 : Right click on SampleSilver.svc and view in browser
it ll show you a url like(http://localhost:50077/SampleSilver.svc?wsdl)
Step8 :Open that , Now copy text shown in URL bar
Step9 :In SampleSilverlight Project add a service Reference with that same URL and Name (sam)
Step10: Paste Follwing code in MainPage.xaml.cs Page
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
sam.SampleSilverClient obj = new sam.SampleSilverClient();
obj.InsertEmployeeCompleted += new EventHandler<sam.InsertEmployeeCompletedEventArgs>(obj_InsertEmployeeCompleted);
obj.InsertEmployeeAsync(textBox1.Text, textBox2.Text);
}
void obj_InsertEmployeeCompleted(object sender, sam.InsertEmployeeCompletedEventArgs e)
{
}
Step 11: Run the Application
ANSI_PADDING OFF
Monday, January 2, 2012
Subscribe to:
Comments (Atom)
Creating Provider hosted app (sharepoint online) with local hosted IIS
The Pre-requires are as follows. 1. Office 365 Subscription 2. Visual Studio 2015 (Professional/Community/Enterprise Edition) With t...
-
SP2013 vs SP2010 As we know Microsoft has released the next version of SharePoint 2010 which is called as SharePoint 2013(p...
-
if (( Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue ) -eq $null ) { Add-PSSnap...
-
Introduction In this article, I will explain how to call ASP.NET web API in your Angular project step by step. You need to enable CORS i...