在手持设备访问其RESTful方法之前,是否需要将ASP.NET Web API应用程序安装到“真正的”IIS中?

时间:2013-11-06 00:54:35

标签: .net asp.net-web-api compact-framework iis-express

我正在尝试在手持设备(Motorola / Symbol 3090和3190)上测试客户端Windows CE / Compact Framework(.NET 3.5)应用程序,但是,虽然“虚假”客户端在桌面上附加并正常工作,桌面上的客户端应用程序无法连接 - 尝试调用RESTful Web API方法时出现400 Not Found错误。

这是在Visual Studio中运行的服务器/ Web API应用程序,由内置/缩小版本的IIS托管。

这是预期的(不连接)?如果没有,问题可能是什么?

更新

注意:在开始>中输入“cmd”后,我不得不按Ctrl + Shift + Enter。运行框(否则我得到“请求的操作需要提升(以管理员身份运行)”)。但请注意我在运行第二个命令(从命令shell复制)后得到的指纹:

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

成功添加了网址

netsh firewall add portopening TCP 80 IISExpressWeb enable ALL

所以既然它“成功执行”我很好 - 不必担心重做它,对吗?我认为指纹是“我知道你的意思,我为你照顾它,但下次你这样做,这样做是另一种方式......”消息类型。

更新2

显然它是doch applicationhost.config,在C:\ Users \ clay \ Documents \ IISExpress \ config中,而不是项目中的application.config。

我在那里:

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

并将其更改为此(IP地址已更改):

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

更新3

我停止并通过在命令行输入“iis”并在IIS管理器中选择“停止”然后“启动”来启动IIS(我希望/假设重新启动IIS与“重新启动IIS Express”相同“Jeow在下面提到过”,但是当我尝试在掌上电脑上运行客户端应用程序时,我仍然得到“无法连接到远程服务器”(在桌面上运行服务器ASP.NET Web API应用程序,从Visual Studio启动2013年)。

我是否需要启动该应用程序而不是VS?如果是这样,怎么样?从VS通过F5运行时,打开的页面位于端口28642上。

我的IIS applicationhost.config文件现在具有以下应用程序:

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

第一个绑定是我的桌面IP地址,第二个绑定是VS在运行此应用程序时使用的端口,第四个是ssl版本(尚未使用,至少没有故意)。

中间的那个是可以在浏览器中看到的(带有ASP.NET verbiage /占位符文本的“主页”)。

所以我想知道是否需要从VS外部启动此应用程序和/或需要在applicationhost.config中删除这些绑定条目中的一个或多个。

更新4

傻傻的我!我没有更改客户端中的代码来引用IP地址而不是localhost。所以我改变了这个:

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

......对此:

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

...在客户端,但它仍然不起作用(虽然它的工作方式不同);我现在得到,“远程服务器返回错误:(404)Not Found。

那里有“80”,或者...... ???

  • 并且applicationhost.config中的绑定应该是这样的,正确的:

    binding protocol =“http”bindingInformation =“*:80:192.112.442.13”

我尝试删除端口号(80),但仍然出现“404”错误...

更新5

我终于克服了这个错误,但有两件事是不同的,所以我不确定它是一个,另一个,或者两者兼而有之。

一)我通过在Target Device comboBox中选择“Windows CE Device”直接从VS 2008部署。我一直在构建项目,然后通过Windows Exploder将.exe复制到手持设备。

其他)我还将我在IP地址的代码中使用的URL更改为我的机器名,IOW来自:

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

...为:

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

所以......我现在正在连接服务器及其RESTful方法!

applicationhost.config中的条目现在是:

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

更新6

现在又回到了404 Not Found错误。那是一个短暂的“瞧”! Que sera sera,我估计......它似乎与一个新的错误信息有关,即“无法启动IIS Express Web服务器”

更新7

好的,在applicationhost.config中,我改变了这个:

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

为:

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

...我把IIS Express拿回来......但为什么呢?也许这个名称(而不是IP地址)让IIS Express感到困惑......我仍然会收到404 Not Found错误,但是...

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

1 个答案:

答案 0 :(得分:2)

您需要配置IIS Express以在您的IP地址上为您的应用程序提供服务。默认情况下,它仅响应您的Mobile模拟器/设备无法看到的localhost。

查看1.让IIS Express通过http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx

中的端口80部分向外部提供服务

引自网站

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" />

然后重新启动IIS Express。

编辑:

在命令行中运行ipconfig以获取当前的IP地址,并将hanselman-w500替换为该IP地址。