1

I'm new in WCF. I am currently working on a project where I explained in my last question posted here --> How can I implement callbacks to another server in c#

I am trying to study callback with an example. It uses Console Application for hosting the service and Windows Forms for client. I must run my server B with Console application instead of Windows Form. Everything was fine when I run the service alone. But when I run my server B(client), an error was displayed:

"The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error."

It was pointing on this code in my serverB(client) code:

public void NotifySubscribe(string subscriberName)
    {
        SendOrPostCallback callback =
           delegate (object state)
           {
               Console.WriteLine(String.Format("{0} has subscribe to service", state.ToString()));
               Console.WriteLine(subscriberName);
               Console.Read();
           };
        _uiSyncContext.Post(callback, subscriberName);
    }

The almost imitated everything from an example that I have. This was the original code of that code above:

public void NotifyGuestJoinedParty(string guestName)
    {
        // The UI thread won't be handling the callback, but it is the only one allowed to update the controls.  
        // So, we will dispatch the UI update back to the UI sync context.
        SendOrPostCallback callback = 
            delegate (object state)
            { this.WritePartyLogMessage(String.Format("{0} has joined the party.", state.ToString())); };

        _uiSyncContext.Post(callback, guestName);
    }

private void WritePartyLogMessage(string message)
    {
        string format = this.txtPartyLog.Text.Length > 0 ? "{0}\r\n{1} {2}" : "{0}{1} {2}";
        this.txtPartyLog.Text = String.Format(format, this.txtPartyLog.Text, DateTime.Now.ToShortTimeString(), message);
        this.txtPartyLog.SelectionStart = this.txtPartyLog.Text.Length - 1;
        this.txtPartyLog.ScrollToCaret();
    }

Because I'm using Console Application in my project, instead of having it in a textbox, I write it using Console.writeline(); I don't know if it is about the delegate(object state) there in the code. Please response. I don't know how to fix the bug. Thank you.

Community
  • 1
  • 1
Brenelyn
  • 593
  • 4
  • 8
  • 15

1 Answers1

0

I am new with WCF as well.

I believe you cannot perform such action in a console application using a duplex service. This question was asked 5 months ago, so I suppose you have found the answer you desire. Please correct me if I am wrong. I'd appreciate it.

Thang Do
  • 316
  • 2
  • 16