- WCF2.zip
- WCF2
- ClientApp
- WindowsFormsApplication1
- Service
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
namespace ClientApp
{
public partial class Form1 : Form
{
bool isSubscribed = false;
Callback callback;
ServiceReference1.CalculatorClient client;
public Form1()
{
InitializeComponent();
callback = new Callback(this);
client = new ClientApp.ServiceReference1.CalculatorClient(new InstanceContext(callback));
}
private void button1_Click(object sender, EventArgs e)
{
try
{
this.richTextBox1.Text += "\nCalling WCF service add method... Add(" + this.textBox1.Text + "," + this.textBox2.Text + ") = " + client.Add(Convert.ToDouble(this.textBox1.Text), Convert.ToDouble(this.textBox2.Text)).ToString();
}
catch (Exception ex)
{
this.richTextBox1.Text = ex.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
if (client.Subscribe())
{
this.richTextBox1.Text += "\nClient subscribed";
isSubscribed = true;
}
else
this.richTextBox1.Text += "\nCould not subscribe client";
}
catch (Exception ex)
{
this.richTextBox1.Text += "\n"+ex.ToString();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if(isSubscribed)
MessageBox.Show("Client unsubscribed..."+ client.UnSubscribe());
}
catch (Exception ex)
{
MessageBox.Show("Could not unsubscribe client");
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
this.richTextBox1.Text += "\nCalling WCF service subtract method... Subtract("+this.textBox1.Text+","+ this.textBox2.Text+") = " + client.Subtract(Convert.ToDouble(this.textBox1.Text), Convert.ToDouble(this.textBox2.Text)).ToString();
}
catch (Exception ex)
{
this.richTextBox1.Text = ex.ToString();
}
}
private void button4_Click(object sender, EventArgs e)
{
try
{
this.richTextBox1.Text += "\nCalling WCF service multiply method... Multiply(" + this.textBox1.Text + "," + this.textBox2.Text + ") = " + client.Multiply(Convert.ToDouble(this.textBox1.Text), Convert.ToDouble(this.textBox2.Text)).ToString();
}
catch (Exception ex)
{
this.richTextBox1.Text = ex.ToString();
}
}
private void button5_Click(object sender, EventArgs e)
{
try
{
this.richTextBox1.Text += "\nCalling WCF service divide method... Divide(" + this.textBox1.Text + "," + this.textBox2.Text + ") = " + client.Divide(Convert.ToDouble(this.textBox1.Text), Convert.ToDouble(this.textBox2.Text)).ToString();
}
catch (Exception ex)
{
this.richTextBox1.Text = ex.ToString();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Javier graduated from Rochester Institute of Technology in 2010 and has been working as a software developer since then