locked
How to handle ajax calls in webview control to route the request to appropriate domain

    Question

  • Hi All,

    I have started to develop windows store app where we want to use all the resources available for our website. So we have started with the below approach :

    1) Host all the resources in the structured file system (HTML5, CSS, Javascript) as zip file in the server.

    2) When the windows store app launch download the zip file from server and explode it in the local app file system in the same structure.

    3) Launch the main window by either hosting the files via offlinehttpservice (e.g : http://localhost:port/rootfolder/resource) in webview or directly navigate using ms-appdata:///local/rootfolder/resource.

    Now with both the approach the initial landing page gets displayed properly. Issue here is all the ajax calls from the javascript file refernced in the html file fails.

    With the offlinehttservice approach i am able to intercept all the outgoing calls at the Socket level by the listener assigned with offlinehttpservice and modify the request to route to appropriate domain since all the ajax calls comes with relative path. But not able to return the response to the calling function.

    Basically i am looking for a solution where all the ajax request can be intercepted, modify the request and get the response (modify if required) and return the handle to calling javascript function.

    If this can be solved the whole web-app would work like a charm as windows store app with minimum level of development.

    Any help would be much appreciated.

    Offlinehttpservice resource : http://offline.codeplex.com/

    Thanks

    Friday, July 25, 2014 12:45 AM

Answers

  • This process violates Store app requirements 3.9:

    3.9 All app logic must originate from, and reside in, your app package

    Your app must not attempt to change or extend the packaged content through any form of dynamic inclusion of code that changes how the application  behaves with regard to Store certification requirements.  Your app should not, for example, download a remote script and subsequently execute that script in the local context of the app package.

    The link you provide about offlinehttpservice also acknowledges this:

    The Reason Behind Doing It This Way
    The way it works is that although the Windows Store App security model does not presently allow the WebView component to view files that are loaded into Storage folders during runtime - such as viewing the contents of a Zip file that was downloaded from the web and expanded into a folder in the Pictures library- the work-around for this is to serve the content from the same location using an In Process HTTP Server; the advantage of this is that any rogue code that was inadvertently downloaded would be sand-boxed by the WebView's http security model!

    Any Store app that does this will be removed from the Store. I've seen it happen already.  I don't recommend that you go this route. 


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, July 25, 2014 1:26 PM
    Moderator

All replies

  • This process violates Store app requirements 3.9:

    3.9 All app logic must originate from, and reside in, your app package

    Your app must not attempt to change or extend the packaged content through any form of dynamic inclusion of code that changes how the application  behaves with regard to Store certification requirements.  Your app should not, for example, download a remote script and subsequently execute that script in the local context of the app package.

    The link you provide about offlinehttpservice also acknowledges this:

    The Reason Behind Doing It This Way
    The way it works is that although the Windows Store App security model does not presently allow the WebView component to view files that are loaded into Storage folders during runtime - such as viewing the contents of a Zip file that was downloaded from the web and expanded into a folder in the Pictures library- the work-around for this is to serve the content from the same location using an In Process HTTP Server; the advantage of this is that any rogue code that was inadvertently downloaded would be sand-boxed by the WebView's http security model!

    Any Store app that does this will be removed from the Store. I've seen it happen already.  I don't recommend that you go this route. 


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, July 25, 2014 1:26 PM
    Moderator
  • Hi there,

    Did you ever find a solution to this? If so I would be most interested.

    Thanks

    Thursday, October 02, 2014 1:51 AM