错误地使用SendOrPostCallback变量(delegate(对象状态))给了我WCF异常:"The server did not provide a meaningful reply"?



我是WCF的新手。我目前正在做一个项目,我在这里发布的最后一个问题中解释了-->我如何在c#中实现对另一台服务器的回调

我试着用一个例子来研究回调。它使用控制台应用程序托管服务,使用Windows窗体托管客户端。我必须用控制台应用程序而不是Windows窗体运行我的服务器B。当我单独运行服务时,一切都很好。但当我运行服务器B(客户端)时,显示了一个错误:

"服务器没有提供有意义的答复;这可能是由于合同不匹配、会话提前关闭或内部服务器错误造成的。">

它指向我的服务器B(客户端)代码中的这段代码:

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);
}

他们几乎模仿了我的一个例子。这是上面代码的原始代码:

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}rn{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();
}

因为我在项目中使用Console应用程序,而不是将其放在文本框中,所以我使用Console.writeline()编写它;我不知道这是否与代码中的委托(对象状态)有关。请回复。我不知道如何修复这个错误。非常感谢。

我也是WCF的新手。

我相信您不能在使用双工服务的控制台应用程序中执行这样的操作。这个问题是5个月前问的,所以我想你已经找到了你想要的答案。如果我错了,请纠正我。我很感激。

相关内容

最新更新