Live Tile Channel推送错误“MessageBadContent”

时间:2011-03-04 07:44:29

标签: windows-phone-7

我正在使用手机将实时磁贴更新推送到自身,但是我收到错误:

{Microsoft.Phone.Notification.NotificationChannelErrorEventArgs}

" MessageBadContent"

errorCode = -2129589899

我有一种感觉这是因为我在Uri中发送的瓷砖太长了。

还有其他人有这个问题吗?

发送更新的代码:

HttpNotificationChannel channel = HttpNotificationChannel.Find("OneTime");
            if (channel != null)
                channel.Close();
            else
            {
                channel = new HttpNotificationChannel("OneTime");
                channel.ChannelUriUpdated +=
                    (s, e) =>
                    {
                        if (imageUri.IsAbsoluteUri)
                        {                       
                            channel.BindToShellTile(new Collection<Uri> {new Uri("http://mydomain.com") });                     
                        }
                        else
                            channel.BindToShellTile();

                        SendTile(e.ChannelUri, imageUri.ToString(), 0, " ",
                                    () =>
                                    {
                                        //Give it some time to let the update propagate
                                        Thread.Sleep(
                                            TimeSpan.FromSeconds(10));

                                        channel.UnbindToShellTile();
                                        channel.Close();
                                        //Do the operation
                                        if (onComplete != null)
                                            onComplete();
                                    }
                            );
                    };
                channel.Open();
            }
        } 

我发送的包中的XML是:

  <?xml version="1.0" encoding="utf-8" ?> 
 <wp:Notification xmlns:wp="WPNotification">
 <wp:Tile>
  <wp:BackgroundImage>http://mydomain.com/t/k/DQAAALcAAADLhwtLmfIY_JXVhUMA4vYEemvu9dlf-rK8_SbiCGdWPyABXu1MqmZePHf5q9KHfL5J24qvWEgc6EgfparQKQCHsn938r357YSY_uci8DU3XUSg_v9HI3Kbbwmxrr6I97QpD99RfEOxwa6KhZiFTlMLLswh8HDRhlJbe-h10p40SnylDumQRhxqiRYbB3sHYPekrVyS8gJf9opaoQ-dIV1PAtKqc_WdrU37pWYHhwjKJ-QV7d0JrQ9sONEr6VitSRc/s/21556645/p/3</wp:BackgroundImage> 
  <wp:Count>0</wp:Count> 
  <wp:Title /> 
  </wp:Tile>
  </wp:Notification>

2 个答案:

答案 0 :(得分:1)

据猜测,WP7代码可能正在使用某些System.IO.Path功能,这对于260个字符的限制很有说服力 - 请参阅http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath - 而这经常会找到Uri代码 - 例如http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/723e6bfd-cab7-417b-b487-67f1dcfa524f

一些可能的解决方法:

答案 1 :(得分:0)

当使用Bing Maps REST API返回地图图像动态生成图块的远程图像Uri时,我也遇到了同样的问题(MessageBadContent)。

图片uri采用以下格式

String.Format(@"http://dev.virtualearth.net/REST/v1/Imagery/Map/Aerial/{0},{1}/10?mapSize=200,200&&pp={2},{3};1;&mapVersion=v1&key={4}", Lat, Lon, Lat, Lon,AppID);

此问题的解决方案是使用Bit.ly API缩短Url

  var BitlyRequest = String.Format(@"http://api.bit.ly/v3/shorten?login=name&apiKey=ApiKey&format=txt&longUrl={0}", HttpUtility.UrlEncode(MapUri));

  var BackgroundImageUri = new Uri(new WebClient().DownloadString(BitlyRequest));