0

I am trying to test a client Windows CE / Compact Framework (.NET 3.5) app on handheld devices (Motorola/Symbol 3090 and 3190), but, although a "fake" client attaches and works fine on the desktop, the client app on the desktop fails to connect - it gets a 400 Not Found error when trying to call a RESTful Web API method.

This is with the server / Web API app running in Visual Studio, hosted by the built-in / scaled-down version of IIS.

Is this to be expected (not connecting)? If not, what might the problem be?

UPDATE

Note: I had to mash Ctrl+Shift+Enter after entering "cmd" in the Start > Run box (otherwise I get "The requested operation requires elevation (Run as administrator)"). But note the fingerwag I got after running the second command (copied from the command shell):

netsh http add urlacl url=http://192.76.42.42:80/ user=everyone

URL reservation successfully added

netsh firewall add portopening TCP 80 IISExpressWeb enable ALL

So since it "executed successfully" I'm fine - don't have to worry about redoing it, correct? I take it that the fingerwag is a "I know what you meant, and I took care of it for you, but next time you do this, do it this other way..." type of message.

UPDATE 2

Apparently it is doch applicationhost.config, in C:\Users\clay\Documents\IISExpress\config, not application.config in the project.

I had this there:

<site name="HandheldServer" id="20">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\HandheldServer\HandheldServer" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:28642:localhost" />
    </bindings>
</site>

and changed it to this (IP Address changed):

<site name="HandheldServer" id="20">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/"   
          physicalPath="C:\HandheldServer\HandheldServer"/>
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:80:176.111.222.42" />
    </bindings>
</site>

UPDATE 3

I stopped and started IIS by entering "iis" at the command line and selecting "Stop" and then "Start" in IIS Manager (I'm hoping/assuming that restarting IIS is the same thing as "restart your IIS Express" mentioned by Jeow below), but I still get "Unable to connect to the remote server" when I try to run the client app on the handheld (with the server ASP.NET Web API app running on the desktop, started from Visual Studio 2013).

Do I need to start that app elsehow than from VS? If so, how? When running it via F5 from VS, the page that opens is on port 28642.

My IIS applicationhost.config file now has this for this app:

<bindings>
    <binding protocol="http" bindingInformation="*:80:176.112.111.25" />
    <binding protocol="http" bindingInformation="*:28642:localhost" />
    <binding protocol="https" bindingInformation="*:44300:localhost" />
</bindings>

where the first binding is my desktop IP address, the second one is the port VS uses when running this app, and the fourth one is the ssl version (not used yet, at least not deliberately).

The middle one is the one that can be seen in the browser (the "Home Page" with the ASP.NET verbiage/placeholder text).

So I'm wondering if I need to start this app externally from VS and/or need to remove one or more of these binding entries in applicationhost.config.

UPDATE 4

Silly me! I had not changed the code in the client to reference the IP address as opposed to localhost. So I changed this:

const string uri = "http://localhost:28642/api/inventoryItems";

...to this:

const string uri = "http://192.112.442.13:80/api/inventoryItems";

...in the client, but it still doesn't work (although it works differently); I now get, "The remote server returned an error: (404) Not Found."

Should I not have the "80" there, or...???

  • and the binding in applicationhost.config should be like so, correct:

    binding protocol="http" bindingInformation="*:80:192.112.442.13"

?

I tried removing the port number (80), and still get the "404" error...

UPDATE 5

I finally got past that error, but two things were different, so I'm not sure whether it was one, the other, or perhaps a combination of both.

One) I deployed directly from VS 2008 by selecting "Windows CE Device" in the Target Device comboBox. I had been building the project and then copying the .exe to the handheld device via Windows Exploder.

The Other) I also changed the URL I was using in the code from my IP Address to my machine name, IOW from:

const string uri = "http://192.112.483.97:80/api/platypups";

...to:

const string uri = "http://DBPlatypus/api/platypups";

So...I am now connecting to the server and its RESTful method!

The entries in applicationhost.config are now:

<binding protocol="http" bindingInformation="*:PLATYPUS" />
<binding protocol="http" bindingInformation="*:28642:localhost" />

UPDATE 6

And now it's back to the 404 Not Found error. That was a short-lived "voila"! Que sera sera, I reckon...it seems to be related to a new err msg, namely, "Unable to launch the IIS Express Web server"

UPDATE 7

Okay, in applicationhost.config, I changed this:

<bindings>
  <binding protocol="http" bindingInformation="*:DBPlatypus" />
  <binding protocol="http" bindingInformation="*:28642:localhost" />
  <binding protocol="https" bindingInformation="*:44300:localhost" />
</bindings>

to:

<bindings>
  <binding protocol="http" bindingInformation="*:28642:localhost" />
  <binding protocol="http" bindingInformation="*:80:192.112.184.42" />
</bindings>

...and I got IIS Express back...but why? Maybe it's true that the name (as opposed to the IP Address) was confusing IIS Express... I'm still getting the 404 Not Found error, though...

const string uri = "http://DBPlatypus:80/api/platypusBills";
const string uri = "http://DBPlatypus/api/platypusBills";
const string uri = "http://192.112.184.42:80/api/platypusBills";
const string uri = "http://192.112.184.42/api/platypusBills";
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • Does your handheld device share the same connection with your desktop? Say if you were to run up a website (http://localhost:) using Visual Studio would your handheld be able to access that address? – luke2012 Nov 06 '13 at 01:05
  • I don't know yet; I'm trying to get this set up based on Jeow's answer, and will then let you know the status. – B. Clay Shannon-B. Crow Raven Nov 06 '13 at 18:36

1 Answers1

2

You need to configure your IIS Express to serve your application on your IP address. By default, it only respond to localhost, which your Mobile emulator/device cannot see.

Look at 1. Getting IIS Express to serve externally over Port 80 section in http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx

Quoted from the site

Run the following in command line
netsh http add urlacl url=http://hanselman-w500:80/ user=everyone
netsh firewall add portopening TCP 80 IISExpressWeb enable ALL


Add to applicationHost.config
<binding protocol="http" bindingInformation="*:80:hanselman-w500" />

Then restart your IIS Express.

Edit:

Run ipconfig in command line to get your current IP address, and replace hanselman-w500 with that IP address.

Jeow Li Huan
  • 3,758
  • 1
  • 34
  • 52
  • How does one "restart IIS Express" - would that happen by closing down and restarting Visual Studio, or is there a less "drastic" way of accomplishing that? – B. Clay Shannon-B. Crow Raven Nov 06 '13 at 17:49
  • Also: I have no application.config in my ASP.NET Web API app; do you mean Web.API, and if so, which one? I'm assuming the "global" one, but there is also one in the Views folder. – B. Clay Shannon-B. Crow Raven Nov 06 '13 at 18:00
  • 1
    Do you mean IIS's ApplicationHost.config instead of a web app's application.config (if there is such a beat) file? That's what Hanselmann's post seems to be talking about... – B. Clay Shannon-B. Crow Raven Nov 06 '13 at 18:49
  • Please see Update 2 for my self-answer to the project's application.config file vs. IIS' applicationhost.config file conundrum. – B. Clay Shannon-B. Crow Raven Nov 06 '13 at 19:03
  • 1
    1. In my experience, using IP address is more reliable. Using the NetBios name DBPlatypus is wonky as sometimes the name could not be resolved. 2. You should be able to access http://192.112.442.13:80/api/inventoryItems from your browser too. If not, check that your IP address is still the same. If still doesn't work try run through Hanselman's instruction again on another port. 3. Unable to start IIS Express might be due to a Windows Update (don't ask me why). Restart your computer and let the update install. – Jeow Li Huan Nov 07 '13 at 03:55
  • I rebooted this morning, but I'm still getting, "Unable to launch the IIS Web Server" – B. Clay Shannon-B. Crow Raven Nov 07 '13 at 16:56
  • See Update 7 for how I got IIS Express back. – B. Clay Shannon-B. Crow Raven Nov 07 '13 at 17:24
  • Do you have any kind of firewall installed, other than Windows Firewall? I noticed your IP address changed. Did you run through Hanselman's procedure again to allow the IIS Express through Windows Firewall? Next would be to configure your router to always give your computer the same IP address. – Jeow Li Huan Nov 08 '13 at 03:15
  • I'll look at Hanselman's article again re: firewall; no worries on the IP address - the ones shown are fake. In actuality, I have the same one always. – B. Clay Shannon-B. Crow Raven Nov 08 '13 at 16:01
  • ...but that article by Hanselmann seems to be specifically about SSL, and I'm not using that for now; just a generic connection. – B. Clay Shannon-B. Crow Raven Nov 08 '13 at 16:11
  • So you're talking about this, to be entered in the cmd shall, correct: "netsh firewall add portopening TCP 80 IISExpressWeb enable ALL"? I already performed the firewall command shell "thing," when I first read and worked through that post. But then I did it again, "just to make sure" (superstition/OCD at work); I still get the failure when trying to read the data from the Web API method, though ("unable to read data" or some such err msg - so apparently it's connecting to the method, just refuses to actually fetch the data). – B. Clay Shannon-B. Crow Raven Nov 08 '13 at 17:46
  • That command is obsolete/deprecated; however, even after I made the firewall safe for democracy (http://stackoverflow.com/questions/19865541/why-does-the-windows-command-shell-tell-me-to-use-a-different-command-and-then-s), I still get the "Unable to read data from the transport connection" exception. – B. Clay Shannon-B. Crow Raven Nov 08 '13 at 19:09