System.InvalidOperationException

KwebenaAcquah-9104 306 Reputation points
2022-04-21T03:28:22.68+00:00

194952-cg.png

i have made a chatting application and i built wcf server side appliation which is to be started when the UI of the chatting application is started but each time i start the application the above picture gives details of my error

i keep getting this error

"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.'"

HERE IS THE IChattingService code:

namespace ChattingInterfaces  
{  
    [ServiceContract(CallbackContract = typeof(IClientContracts))]  
    public interface IChattingService  
    {  
        [OperationContract]  
        int Login(string userName);  
  
        [OperationContract]  
        void SendMessage(string message, string userName);  
  
        [OperationContract]  
        void Logout();  
    }  
}  

MAIN WINDOW CODE;

using ChattingInterfaces;  
using System;  
using System.ServiceModel;  
using System.Windows;  
  
namespace ChattingUI  
{  
    /// <summary>  
    /// Interaction logic for MainWindow.xaml  
    /// </summary>  
    public partial class MainWindow : Window  
    {  
        public static IChattingService Server;  
        private static DuplexChannelFactory<IChattingService> duplexChannelFactory;  
        public MainWindow()  
        {  
            InitializeComponent();  
  
            duplexChannelFactory = new DuplexChannelFactory<IChattingService>(new UserCallback(), "ChatServiceEndPoint");  
            Server = duplexChannelFactory.CreateChannel();  

        

Please some one should help me solve this problem i have tried to comprehend but i can't please help me out to start up my server and my UI at the same run time because i can't achieve this alone;
please help me out

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,641 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,640 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 28,841 Reputation points Microsoft Vendor
    2022-04-21T09:53:16.36+00:00

    Hi @KwebenaAcquah-9104 ,

    "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.


0 additional answers

Sort by: Most helpful