开发者

need to merge two classes together

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 Message开发者_运维问答2Client(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!


You don't need to merge your class with the form: you need to create an instance of it. Something like this:

IServerWCallback server = new ServerWCallbackImpl();
server.Message2Client("hello world");

However (from the structure of your code so far), you'll probably need to have created an instance of the class earlier. This allows you to connect that instance and keep it around for later operation.

You may also want to read the MSDN pages on classes and objects (instances of classes) to make sure you've understood the concepts fully before you continue - this stuff is pretty fundamental to .NET programming.


What is the Need for merging why can't You Use Inheritance?

Solving Multiple Inheritance in C#.net

Click this for more details (stackoverflow)

i think that will give you the answer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜