WCF Application and Instance Management by using 3 different application domains (Asp.net, C # Windows Application and WPF application as clients)

Plz refer to the previous article

 

Part-3 Creating WPF Client

Code for WPF client Application

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using System.Data;

 

namespace WpfClient

{

/// <summary>

/// Interaction logic for Window1.xaml

/// </summary>

public partial class Window1 : Window

{

ServiceReference1.IService PersonalInfo = new ServiceReference1.ServiceClient();

ServiceReference1.PersonalInfo Pi = new ServiceReference1.PersonalInfo();

DataTable dt = new DataTable();

public Window1()

{

InitializeComponent();

dt = new DataTable();

Pi.p_name = "Ankit";

dt = PersonalInfo.GetPersonalInfo(Pi);

// dataGridView1.DataSource = dt;

textBox2.Text = Convert.ToString(dt.Rows[0]["FirstName"]);

textBox3.Text = Convert.ToString(dt.Rows[0]["LastName"]);

textBox4.Text = Convert.ToString(dt.Rows[0]["Country"]);

textBox5.Text = Convert.ToString(dt.Rows[0]["City"]);

textBox6.Text = textBox2.Text = Convert.ToString(PersonalInfo.ReturnVal());

}

 

private void button1_Click(object sender, RoutedEventArgs e)

{

InitializeComponent();

dt = new DataTable();

Pi.p_name = textBox1.Text;

dt = PersonalInfo.GetPersonalInfo(Pi);

textBox2.Text =Convert.ToString(dt.Rows[0]["FirstName"]);

textBox3.Text = Convert.ToString(dt.Rows[0]["LastName"]);

textBox4.Text = Convert.ToString(dt.Rows[0]["Country"]);

textBox5.Text = Convert.ToString(dt.Rows[0]["City"]);

textBox6.Text = Convert.ToString(PersonalInfo.ReturnVal());

 

 

}

}

}

 

Windows1.XAML file

<Window x:Class="WpfClient.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="WPF Client" Height="280" Width="634">

<Grid Width="509">

<TextBox Height="23" Margin="138,14,251,0" Name="textBox1" VerticalAlignment="Top" />

<Label Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="label1" VerticalAlignment="Top" Width="120">Enter Name</Label>

<Button Height="23" HorizontalAlignment="Right" Margin="0,17,144,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click">Search</Button>

<TextBox Margin="138,72,251,0" Name="textBox2" Height="23" VerticalAlignment="Top" />

<TextBox Margin="138,119,251,103" Name="textBox3" />

<TextBox Height="23" Margin="138,0,251,63" Name="textBox4" VerticalAlignment="Bottom" />

<TextBox Height="23" Margin="138,0,251,20" Name="textBox5" VerticalAlignment="Bottom" />

<Label Height="28" HorizontalAlignment="Left" Margin="12,70,0,0" Name="label2" VerticalAlignment="Top" Width="120">First Name</Label>

<Label HorizontalAlignment="Left" Margin="12,119,0,94" Name="label3" Width="120">Last Name</Label>

<Label Height="28" HorizontalAlignment="Left" Margin="12,0,0,60" Name="label4" VerticalAlignment="Bottom" Width="120">Country</Label>

<Label Height="28" HorizontalAlignment="Left" Margin="12,0,0,17" Name="label5" VerticalAlignment="Bottom" Width="120">ID</Label>

<TextBox Height="23" HorizontalAlignment="Right" Margin="0,72,-1,0" Name="textBox6" VerticalAlignment="Top" Width="120" />

<Label Height="28" HorizontalAlignment="Right" Margin="0,72,125,0" Name="label6" VerticalAlignment="Top" Width="120">Service Object Count</Label>

</Grid>

</Window>

 

Below is the WPF form Design.

 

So far we have only designed our Wcf service and 3 clients which are consuming it.Now we will start with Instance management.

Tags:

WCF

Pingbacks and trackbacks (1)+