【发布时间】:2013-02-11 06:05:21
【问题描述】:
我正在构建一个用于推送通知的 WCF 应用程序,其中用户必须先订阅自己,然后订阅客户端从 WCF 获得响应。
我在 WCF 中使用 wsDualHttpBinding 作为绑定和回调。
我不想从客户端调用递归函数。我在 WCF 中使用计时器,当数据库中发生任何更新时,WCF 会抛出消息。我的 WCF 已准备就绪,但无法在客户端显示消息。
现在我的问题是 当客户端从 WCF 获得响应时如何显示消息。
我在 aspx.cs 上的客户端代码是:
public void SendResult(string message)//I got message = "Test String"
{
Response.Write(message);// it throw error "Response is not available in this context."
// I also use this code
HttpContext.Current.Response.Write(message); // but it also give error "Object reference not set to an instance of an object."
}
这是一个非常关键的问题,我只需要显示消息
任何帮助将不胜感激。
编辑 1
服务方法调用
protected void Page_Load(object sender, EventArgs e)
{
SocialProfilesService.SocialClient client =
new SocialProfilesService.SocialClient(new InstanceContext(this));
client.Subscribe(userid)
}
编辑 2
我也试过
SynchronizationContext uiSyncContext;
uiSyncContext = SynchronizationContext.Current;
public void SendResult(string message)//I got message = "Test String"
{
SendOrPostCallback callback = delegate(object state)
{
Response.Write(message);
};
uiSyncContext.Post(callback, message);
}
但它也给了我错误“对象引用未设置为对象的实例”。 怎么办
【问题讨论】:
-
你能展示一下服务方法是如何被调用的吗?
-
请参阅下面我的答案中的链接。
-
我已经看过这篇文章了。我根据这篇文章准备我的服务。但注意到 find 适合在网络上显示消息。
-
重点是你能得到任何东西或某种错误吗?您如何确保您的订阅者工作正常。我在这里无法理解问题出在服务上还是只是显示一条消息?
-
@Tabish:服务工作正常。问题是只在网络上显示消息。我也收到了回复,但无法显示。
标签: c# multithreading push-notification duplex wcf-callbacks