开发者

Live Tile Channel push error "MessageBadContent"

I am using the phone to push a live tile update to itself, however i am receiving the error:

{Microsoft.Phone.Notification.NotificationChannelErrorEventArgs}

"MessageBadContent"

errorCode = -2129589899

i have a feeling this is because the URL i am sending in the Uri for the tile is too long.

has anyone else had this issue?

the code sending the update:

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

the XML in my sent package is:

  <?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>


At a guess, the WP7 code might be using some System.IO.Path functionality and this is infamous for having a 260 character limit - see http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#maxpath - and this quite often finds its way across to Uri code - e.g. http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/723e6bfd-cab7-417b-b487-67f1dcfa524f

Some possible workarounds:

  • If you can rewrite that request as using uglier QueryParam's then it might just work - e.g. if you can reorganise your URL into a from like http://mydomain.com/img/tile/p/23232/fetch?longval=2332323...33e== then this path processing might work.

  • Can you use something like the bitly API to shorten the URL - http://code.google.com/p/bitly-api/wiki/ApiDocumentation ?

  • If you are looking for just a small (300 down to 260) improvement then can you optimise your URL by using shorter names and by using something more compact than Base64 encoding - e.g. http://en.wikipedia.org/wiki/Ascii85 or better? (I suspect the answer to this depends on your web server)


I also had the same problem (MessageBadContent) when the remote image Uri for the tile was dynamically generated by using Bing Maps REST API returning a map image .

The image uri was in the following format

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

The solution for this issue was to shorten the Url by using the Bit.ly API

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜