0

I have a Metro app in C# & XAML. The tile is updated periodically and I've used WebAPI to serve the tile notification XML. So far so good. I was then told that I cannot use WebAPI as the server that I was planning to host it on does not have .NET 4.5. No plans to install it anytime soon either. I had to change the WebAPI to a plain old Web service (.NET 3.5) which does the same thing - return tile notification XML. I've enabled HTTP-GET (I know, security concern) and was able to invoke the webservice like this -

http://server/TileNotifications.asmx/GetTileData?user=user@domain.com

But ever since I made the switch, the tiles are not being updated. I've checked Fiddler and made sure the app is hitting the webservice and the XML is being returned correctly. But the tiles are not updated. If I replace it with the WebAPI, the tiles are updated.

Do I need to do anything special with the web services? like decorating the web method with a custom attribute? Here's my web service code -

[WebMethod]
        public XmlDocument GetTileData(string user)
        {
           // snip

            var xml = new XmlDocument();
            xml.LoadXml(string.Format(@"<tile>
                                      <visual>
                                        <binding template='TileWideSmallImageAndText02'>
                                          <image id='1' src='http://server/images/{0}_wide.png'/>
                                          <text id='1'>Custom Field : {1}/text>
                                          <text id='2'>Custom Field : {2}</text>
                                          <text id='3'>Custom Field : {3}</text>
                                        </binding>
                                        <binding template='TileSquarePeekImageAndText01'>
                                          <image id='1' src='http://server/images/{0}_square.png'/>
                                          <text id='1'>Custom Field</text>
                                          <text id='2'>{1}</text>
                                        </binding>    
                                      </visual>
                                    </tile>", value1, value2, value3, value4));

            return xml;
        }
John Saunders
  • 160,644
  • 26
  • 247
  • 397
tempid
  • 7,838
  • 28
  • 71
  • 101
  • Oddly that code doesn't compile for me unless I change the return to XmlDocument. Does the response from the ASMX service include the XML document header? I suspect your WebAPI one does not. – Jim O'Neil Oct 16 '12 at 01:52
  • @JimO'Neil: Thanks for pointing that out. I've updated the question to return XmlDocument. The WebAPI returns `HttpResponseMessage` which contains `XDocument.Parse(...).Root` (XElement). – tempid Oct 16 '12 at 17:00
  • right but what does the response payload look like in Fiddler? The ASMX code is returning the header which isn't going to work. – Jim O'Neil Oct 16 '12 at 17:44
  • You're right. The response from Web Service has `` in the header, but the response from WebAPI doesn't have it. How do I remove that header in Web Service? `string.replace` or something? – tempid Oct 16 '12 at 18:35
  • I've tried a few things, but for ASMX not sure. For a WCF service, which is still 3.5, you can use the [raw programming model](http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx), essentially returning System.IO.Stream – Jim O'Neil Oct 16 '12 at 20:18
  • @JimO'Neil: I'll try the WCF route. Anything else you can think of? Will a HTTP Handler (.ashx) work? – tempid Oct 16 '12 at 22:13
  • @JimO'Neil: why is it a problem for there to be an XML header? – John Saunders Oct 16 '12 at 23:41
  • yes suspect the handler would work, but more moving parts. I've used the raw WCF scenario successfully just for this purpose, BTW. – Jim O'Neil Oct 16 '12 at 23:41
  • @JimO'Neil: I tried the WCF route and it complains about metadata not found. I'm trying to create the svc in a web service project, may be that's why. But I tried the ASHX method, I got the fragment just like I wanted (no XML declaration) but the tile is still not updated! Here's the response from WebAPI and ASHX - http://pastebin.com/LLvyS0r9. This is frustrating! – tempid Oct 17 '12 at 00:09
  • @JohnSaunders You are correct, sir. I could have sworn in the past this did not work, but it does seem fine with the header. My apologies for the red herring. – Jim O'Neil Oct 17 '12 at 00:35
  • @JimO'Neil: now that you've discovered this, what would you like to do with your other question: http://stackoverflow.com/questions/12924112/remove-xml-declaration-from-web-service-response? – John Saunders Oct 17 '12 at 00:41
  • I'm not spotting a different in the responses. Are you using the Simulator to test? I know you have to restart for the changes to kick in. Likewise when running on machine, I've noticed once or twice having to switch from small to large (or vice versa) to trigger the change. I assume the images referenced are the same in each case (there are img size restrictions)? – Jim O'Neil Oct 17 '12 at 00:43
  • @JimO'Neil: Finally, I got it to work using the WCF Raw model. I know there are image restrictions. I was referencing the same images from the WebAPI call. I learnt something today! Could you please create a new answer below so I can mark it accepted? – tempid Oct 17 '12 at 00:46
  • @JohnSaunders: I'm guessing you were referring to me. I've updated the question to use HttpHandler instead. Will that suffice? Thanks! – tempid Oct 17 '12 at 00:47
  • I apologize. @JimO'Neil has discovered that the XML declaration is not a problem (see his comment). Since that wasn't the problem, your question no longer seems appropriate. – John Saunders Oct 17 '12 at 00:50
  • @JimO'Neil: Are you sure the XML declaration is not a problem? I'm testing the code right now and it doesn't work. I'm using VS 2012 RTM, .NET 4.5 RTM. – tempid Oct 17 '12 at 00:52
  • may want to take this offline, my contact info in my profile. But try http://jimoneil.blob.core.windows.net/tiles/dealsapiens2.xml as a tile source, it works for me and has the xml header in it – Jim O'Neil Oct 17 '12 at 01:05

0 Answers0