- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在编写一个 Windows Phone 7 应用程序,它利用推送通知并有一个类负责管理 MS 通知服务器与我在云中的服务之间的交互。但是,当我尝试在我的设备上打开 channel 时,HttpNotificationChannel 抛出 InvalidOperationException 并显示消息“无法打开 channel ”。根据MSDN我应该尝试再次打开 channel 。
我打开推送通知的代码片段遵循以下标准模式;
public class HttpNotification {
private const string kChannelName = "MyApp.PushNotification";
private HttpNotificationChannel _Channel;
public void Register() {
try {
_Channel = HttpNotificationChannel.Find(kChannelName);
if (_Channel == null) {
_Channel = new HttpNotificationChannel(kChannelName);
InstallEventHandlers();
// This line throws
_Channel.Open();
} else {
InstallEventHandlers();
};
} catch (InvalidOperationException ex) {
MessageBox.Show(string.Format("Failed to initialise Push Notifications - {0}", ex.Message));
};
}
}
我不确定 MSDN 中“尝试再次打开 channel ”的确切含义。我已经将对 Open() 的调用包装在 try/catch 中,并在两次尝试之间暂停 5 秒,但它没有成功。我还在整个方法中尝试了相同的方法(即每次抛出时都调用 HttpNotificationChannel.Find())但无济于事。
我知道这有点含糊 - 但想知道是否有人对处理此问题有任何建议?同样的代码在模拟器中运行完美,但在我的实际设备上每次都失败,即使在卸载并重新安装我的应用程序之后也是如此。鉴于这是我的真实手机,我不太愿意进行硬件重置,希望它能解决这个问题,并且在这个问题困扰我的情况下,我不愿意将应用程序发布到市场。
更新:另外一点,我使用的是未经身份验证的 channel ,因此没有为我的基于云的服务安装证书。
更新 #2:此外,我刚刚尝试将 Microsoft Phone Push Recipe 部署到我的设备上,它也抛出了同样的异常。
最佳答案
因此,从您的评论中我了解到它确实可以在您的模拟器上运行,但不能在您的手机上运行,对吗?您是否曾在其他/之前的申请中使用过 channel 名称?
问题是模拟器每次关闭时都会重置回默认状态,而您的手机不会。特定的 channel 名称只能由单个应用程序使用。因此,如果 channel 名称在同一手机上的另一个应用程序使用之前仍然注册到该应用程序,则您无法从您的应用程序访问它。
相反,一个应用程序也可以注册不超过一个 channel ,因此如果已经有一个与它关联的另一个名称,您将无法注册一个新 channel ,直到您取消注册旧 channel 并重新启动您的设备。也无法请求哪个 channel 与您的应用相关联。
最终,当我陷入这个循环时,我更改了 channel 名称和我在 WMAppManifest.xml 中注册的应用程序 ProductID,它再次从我这里开始工作
<App xmlns="" ProductID="{d57ef66e-f46c-4b48-ac47-22b1e924184b}"
更新我的电脑这个周末死机了,感谢上帝的 WHS 和备份。不管怎样,下面是我的源代码。我注意到两个不同之处。
首先,我创建了一个名为 RepeatAttemptExecuteMethod()
的方法,我将整个执行代码作为委托(delegate)传递给该方法。最后某处 float 的 10 是它必须重试的次数。如果您仅每 5 秒重试一次 .Open
方法,不同之处可能在于我还再次调用了 Find 和 New 方法...
我看到的另一个区别是我的代码假定 _appChannel.ChannelUri 可以为 null。在这种情况下,它会等待 channel 引发事件,然后执行与实际 channel 相关的工作。但是由于您的示例代码不执行任何此类工作,我怀疑它是否是您要找的东西
protected override void Load(PhoneApplicationPage parent)
{
Verkeer.Helper.ExternalResources.RepeatAttemptExecuteMethod(() =>
{
_appChannel = HttpNotificationChannel.Find(CHANNELNAME);
if (_appChannel == null)
{
_appChannel = new HttpNotificationChannel(CHANNELNAME);
SetUpDelegates();
}
else
{
SetUpDelegates();
//if (_appChannel.ChannelUri != null) this.NotificationChannel = _appChannel.ChannelUri;
}
if (_appChannel.ChannelUri != null) this.NotificationChannel = _appChannel.ChannelUri;
else
{
try
{
_appChannel.Open();
}
catch { }
}
BindToShellTile();
App.ViewModel.TrafficInfo.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(TrafficInfo_PropertyChanged);
if (App.ViewModel.TrafficInfo.TrafficImage != null && this.NotificationChannel != null)
{
CreateTiles();
}
},10);
}
private void BindToShellTile()
{
if (!_appChannel.IsShellTileBound && App.ViewModel.PanItemSettings.AutomaticallyUpdateTile)
{
Collection<Uri> ListOfAllowedDomains = new Collection<Uri> { new Uri("http://m.anwb.nl/") };
_appChannel.BindToShellTile(ListOfAllowedDomains);
}
}
void TrafficInfo_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "TrafficImage")
{
if (App.ViewModel.PanItemSettings.AutomaticallyUpdateTile && this.NotificationChannel != null)
{
CreateTiles();
}
}
}
关于c# - HttpNotificationChannel Open() 抛出 InvalidOperationException ("Failed to open channel"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5154135/
我很好奇为什么以下不起作用。一般select用default:防止死锁,但在这种情况下不是: package main import "fmt" func main () { a := mak
我一生都无法弄清楚如何切换图像排序。图像以 (x,x,3) 格式读取,theano 要求它是 (3,x,x) 格式。我尝试更改顺序numpy.array([img[:,:,i] for i in ra
我正在向 libnl 发送单个 SSID 和频率进行扫描,但我得到了多个扫描结果以及我请求的 SSID 和频率,但我需要单个扫描结果(仅适用于请求的 SSID),如何实现这一点。请帮助我,我也发送了我
我是 Golang 的新手,但正在努力理解这门伟大的语言!请帮帮我.. 我有 2 个 channel 。 “进”和“出” channel in, out := make(chan Work),
例如我有这段代码: package main import ( "fmt" ) func main() { c1 := make(chan interface{}) close
我们使用以下调用来获取经过身份验证的用户的 ChannelID,它适用于大多数情况。一些 YouTube 用户将他们的 channel 连接到 Google+ 信息页,但在这种情况下,我们的一位用户无
case 'sinfo': const sinfo = new Discord.MessageEmbed() .addField('Server Name 🔎 :', message.guild.n
我需要让所有 channel 来创建一个 bunker 命令,这使得所有 channel 都是只读的。 最佳答案 他们变了Client.servers至 Client.guilds在 newer ve
为什么当第二个值通过另一个 go routine 发送并且没有收到发送的第一个值时, channel c 没有缓冲? package main import "fmt" func sum(s []in
据我所知,内置的 split 会将一个 3 channel Mat 拆分为三个 1 channel Mat。结果,这三个 Mat 只是具有一些不同强度的灰度。 我的意图是获得三个 3 channel
如何检测当前的 RAM 配置?我需要询问 Windows RAM 当前是在单 channel 、双 channel 还是四 channel 中运行。 我搜索了很多,并没有在这个网站或其他网站上找到任何
我需要拆分一个多 channel wav 文件并将每个 channel 编码为 mp3 文件。 我知道 gtresamer 的 deinterleave 插件,但我不确定如何将它用于 wav 文件以及
关闭。这个问题需要details or clarity .它目前不接受答案。 想要改进这个问题吗? 通过 editing this post 添加详细信息并澄清问题. 关闭 8 年前。 Improve
我正在尝试运行 Hyperledger Fabric 网络,它由单个订购者、单个对等节点和一个 cli 组成。为了学习启动 Hyperledger Fabric 网络的过程,从创建与加密相关的工件到将
我在 Laravel 中使用事件广播。我正在使用基于角色的通知访问权限。我有用于广播的自定义 auth guard。当用户连接到 channel 时,客户端将具有内部权限的 access_token
我正在编写一个使用 Elixir Channels 来处理实时事件的应用程序。我知道每个客户端将打开 1 个套接字,并且可以在其上多路复用多个 channel 。所以我的应用程序是一个聊天应用程序,其
我有一些 .wav 文件,我想转换它们的频率 (fs) 和 channel 数 (nchannels)。我在jupyter笔记本python3.6上使用ffmpeg。我使用了以下命令并且它有效。 cm
我有一个视频渲染器,它需要两个 H265 流(YUV420),我需要烘焙它们以使它们中的一个与另一个形成 alpha 蒙版。这一切都已解决并且效果很好,但是如果我按照此处的说明进行操作: ffmpeg
我运行此命令以便能够将 udp 直播流传输到可使用正在构建的移动应用程序播放的 http 直播流。 它只是一个只有音频流的流。 ffmpeg -i udp://@localhost:1111 -map
我在我的 discord.js 机器人中创建了 nuke 命令,它创建了具有相同名称、权限、主题等的 channel ,并删除了“原始” channel 。但是有一个问题,如何使 channel 与“
我是一名优秀的程序员,十分优秀!