Hi @Kwebena Acquah ,
"System.InvalidOperationException: 'The callback contract of contract IChattingService either does not exist or does not define any operations. If this is not a duplex contract, consider using ChannelFactory instead of DuplexChannelFactory.'"
As the error says. Maybe you can try to use ChannelFactory
instead of DuplexChannelFactory
, you can refer to the code below.
I didn't find a reference to wcf in your mainwindow code, e.g. using WindowsFormsApp1.ServiceReference1,
you can check the documentation on how to add a wcf reference.
https://learn.microsoft.com/en-us/visualstudio/data-tools/how-to-add-update-or-remove-a-wcf-data-service-reference?view=vs-2022
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("***");
ChannelFactory<IChattingService> factory = new ChannelFactory<IChattingService>(binding, address);
Server = factory.CreateChannel();
}
public IChattingService Server { get; private set; }
public void RecieveMessage(string message, string userName)
{
textBox1.Text += DateTime.Now + "\n" + userName + ":" + message + "\n";
}
Edit
NetTcpBinding binding = new NetTcpBinding();
EndpointAddress addr = new EndpointAddress("net.tcp://localhost:8000/ChatService");
ChannelFactory<IChattingService> chn = new ChannelFactory<IChattingService>(binding, addr);
Server = chn.CreateChannel();
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.