Go to the design part of this form and change this piece of code ..
protected override void Dispose(bool disposing)
{
if (disposing)
{
foreach (IChannel channel in ChannelServices.RegisteredChannels)
{
try
{
ChannelServices.UnregisterChannel(channel);
}
catch (Exception ex)
{
Debug.WriteLine("Client.Dispose exception: " + ex);
}
}
if (components != null)
components.Dispose();
}
base.Dispose(disposing);
}
Double click the submit button i generate event handler and copy ,paste following codes ..
namespace StudentRemotingServiceClient
{
public partial class LISTOFRECORD : Form
{
public LISTOFRECORD()
{
InitializeComponent();
RegisterBinaryTcpClientChannel();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void LISTOFRECORD_Load(object sender, EventArgs e)
{
try
{
var remService = (StudentRemotingService.IStudentRemotingService)Activator.GetObject(typeof(StudentRemotingService.IStudentRemotingService), "tcp://localhost:500/Insert.rem");
dataGridView1.DataSource= remService.Get();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void RegisterBinaryTcpClientChannel(string name = "tcp client")
{
IClientChannelSinkProvider firstClientProvider;
IServerChannelSinkProvider firstServerProvider;
var channelProperties = new Hashtable();
channelProperties["name"] = name;
channelProperties["typeFilterLevel"] = TypeFilterLevel.Full;
channelProperties["machineName"] = Environment.MachineName;
channelProperties["port"] = 0; // auto
// create client format provider
var clientProperties = new Hashtable();
clientProperties["typeFilterLevel"] = TypeFilterLevel.Full;
var clientFormatProvider = new BinaryClientFormatterSinkProvider(clientProperties, null);
firstClientProvider = clientFormatProvider;
// create server format provider
var serverFormatProvider = new BinaryServerFormatterSinkProvider(null, null);
serverFormatProvider.TypeFilterLevel = TypeFilterLevel.Full;
firstServerProvider = serverFormatProvider;
TcpChannel tcp = new TcpChannel(channelProperties, firstClientProvider, firstServerProvider);
ChannelServices.RegisterChannel(tcp, false);
}
}
}
If you done everything correctly you will be able to display the data when submit button is clicked before that make sure the host is running .
No comments:
Post a Comment