Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I've create a tcp WCF service from windows form. The operationcontract that i implemented will update the text of a textbox. but When client call that operation, the textbox doesn't show that text. How to solve this?

This is my server:

C#
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;
using MiniChat;
namespace MiniChatServer
{
    public partial class FrmMiniChatServer : Form, IServerContract
    {
        private ServiceHost host;
        public FrmMiniChatServer()
        {
            InitializeComponent();
        }
        private void MiniChatServer_Load(object sender, EventArgs e)
        {
            host = new ServiceHost(typeof(FrmMiniChatServer));
            host.Open();
        }
        #region IServerContract Members
        public void ClientToServer(string msg)
        {
            textBox1.Text = "Client: " + msg;
            MessageBox.Show(textBox1.Text);
        }
        #endregion
        private void MiniChatServer_Closed(object sender, FormClosedEventArgs e)
        {
        }
    }
}


And Client

C#
ServerServices.IServerContract server = new ServerServices.ServerContractClient();
server.ClientToServer("message from client");



and contract interfaces

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
namespace MiniChat
{
    public interface ICallback
    {
        [OperationContract(IsOneWay=true)]
        void ServerToClient(string msg);
    }
    [ServiceContract(CallbackContract=typeof(ICallback))]
    public interface IServerContract
    {
        [OperationContract(IsOneWay=true)]
        void ClientToServer(string msg);
    }

}


In the function:
C#
public void ClientToServer(string msg)
{
    textBox1.Text = "Client: " + msg;
    MessageBox.Show(textBox1.Text);
}

MessageBox.Show(textBox1.Text); show message correctly, but textBox1 doesn't show anything.
Posted
Updated 14-Apr-11 18:35pm
v11
Comments
Pong D. Panda 14-Apr-11 23:05pm    
Show the code on both sides and we might help.
Sergey Alexandrovich Kryukov 14-Apr-11 23:10pm    
How can you even imaging any help based on your information? Try to think about it.
--SA
Pong D. Panda 14-Apr-11 23:13pm    
Is it working now? Why tagged as solved?
thanhvinh0906 14-Apr-11 23:18pm    
I'm sorry, i've just updated my question
thanhvinh0906 15-Apr-11 0:33am    
I've just updated my question again

1 solution

I see what you'r doing here. Although your naming convention is really confusing.

Replace

C#
void IServerContract.ClientToServer(string msg) {
     textBox1.Text = "Client: " + msg;
}


with
C#
public void ClientToServer(string msg) {
     textBox1.Text = "Client: " + msg;
}


Then go to your IServerContract Class and define the Interface for ClientToServer

C#
public void ClientToServer(string msg);


Then update your client code.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900