I'm trying to name a server-client messaging application using wcf.
Here's the server part so far.
namespace server
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) /// once the form loads, create and open a new ServiceEndpoint.
{
ServiceHost duplex = new ServiceHost(typeof(ServerWCallbackImpl));
duplex.AddServiceEndpoint(typeof(IServerWithCallback), new NetTcpBinding(), "net.tcp://localhost:9080/DataService");
duplex.Open();
this.Text = "SERVER *on-line*";
}
private void buttonSendMsg_Click(object sender, EventArgs e)
{
Message2Client(textBox2.Text); /// The name 'Message_Server2Client' does not exist in the current context :(
}
class ServerWCallbackImpl : IServerWithCallback /// NEED TO SOMEHOW MERGE THIS ONE WITH THE FORM1 CLASS
{
IDataOutputCallback callback = OperationContext.Current.GetCallbackChannel<IDataOutputCallback>();
public void StartConnection(string name)
{
/// client has connected
}
public void Message_Cleint2Server(string msg)
{
TextBox1.text += msg; /// 'TextBox1' does not exist in the current context :(
}
public void Message2Client(string msg)
{
callback.Message_Server2Client(msg);
}
}
[ServiceContract(Namespace = "rf.services",
CallbackContract = typeof(IDataOutputCallback),
SessionMode = SessionMode.Required)]
public interface IServerWithCallback ///// what comes from the client to the server.
{
[OperationContract(IsOneWay = true)]
void StartConnection(string clientName);
[OperationContract(IsOneWay = true)]
void Message_Cleint2Server(string msg);
}
public interface IDataOutputCallback ///// what goes from the sertver, to the client.
{
[OperationContract(IsOneWay = true)]
void AcceptConnection();
[OperationContract(IsOneWay = true)]
void Message_Server2Client(string msg);
}
}
}
I just can't figure out, how do I merge "class Form1:Form" and "class ServerWCallbackImpl : IServerWithCallback", so that I would be able to induce the Message2Client function from a buttonclick, as well as add TextBox1.text += msg when the *Message_Cleint2Server* happens.
Thanks!