Sony Arouje

a programmer's log

VS2013 Multi-Device Hybrid Apps and Network Error in Windows8

with 2 comments

Last couple of days I was working on Node js REST service running in one of my Raspberry Pi. The idea is to do certain stuffs remotely via mobile devices. Later I will write a post explaining the project in detail. I completed Phase 1 of the application running in Raspberry pi. So next task was creating a mobile app, I decided to use Cordova with VS 2013 Multi Device Hybrid app template.

Yesterday night I started working on the Hybrid app in VS 2013 for Windows 8. First thing I wanted to test was the connectivity to the REST service running in Raspberry pi. I used Angular js $http to connect to the REST service. To my surprise what ever I do, the app is throwing error while doing http post with status 0. The same code works successfully if I run as a web app.

I spend a hell lot of time to figure out the issue but no success. Then I decided to use fiddler to test the traffic, when fiddler is running the app could able to communicate with the REST service. I got a hint, when we run Fiddler in Win8, it adds apps to AppContainer Loopback exemption. If I exempt my windows 8 app then http request starts failing. This stage I realized that, the error is because of some app configuration issue. Also in VS Java Script console I could see the error as shown below.

XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd.

All my google search return nothing. After a long hours of desperate research I came to know that to access private network I need to add Private Network capability to windows 8 app. But I didn’t know how to add it for Hybrid app as there is no Capabilities section in the config.xml. Some more search leads me to the Faq page of Multi device hybrid app template. As per the FAQ page we can override the default AppManifest.xml as shown below.

1. Create a Package.appxmanifest file under res/cert/windows8. Create a windows8 solution folder if not exist.

2. Open the project folder and go to bld/windows-AnyCpu/Debug and open AppxManifest.xml in notepad, copy the content and paste it in the above Package.appxmanifest file.

3. Double click on Package.appxmanifest file then goto Capabilities tab and choose ‘Private Networks (Client & Server)’.

4. Save it and run the app again, this time it worked I could connect to my Node js REST api.

 

Hope this will help some one to solve the XMLHttpRequest issue.

 

Happy Coding…

Advertisements

Written by Sony Arouje

October 29, 2014 at 3:50 pm

2 Responses

Subscribe to comments with RSS.

  1. Hi!

    I’m with the same problem. I created a Asp.Net WebAPI in VS2015 for my backend and AngularJS with HTML for my frontend. I didn’t find a place where I can create a Package.appxmanifest in VS0215 with Web API project\solution. I searched for some links and find some instructions but with no sucess.
    Can you help-me? (I have the problem just with Edge webrowser)

    Thanks! Best Regards

    Murilo (Brazil)

    December 21, 2015 at 10:31 am

  2. H!

    I’m with the same problem. I created a WebAPI solution with VS2015 for the backend and AngularJS with HTML for my frontend. I get the same error when I try to get or post something from my backend (Just with Edge Webrowser). I didn’t find how to create a Package.appxmanifest in VS2015. Can you help-me?

    Thanks! Best Regards

    muriloclau

    December 21, 2015 at 10:38 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: