WebAPI - 在本地工作但在远程服务器上收到404错误

时间:2016-05-02 15:33:56

标签: c# asp.net asp.net-web-api

这有效......

client.BaseAddress = new Uri("http://localhost/InventoryApi/");

这失败了......

client.BaseAddress = new Uri("http://yyyZLtd.com/");

在Win Server 2012 R2上运行IIS 8.5的远程服务器

完整代码......

client.BaseAddress = new Uri("http://localhost/InventoryApi/");

client.BaseAddress = new Uri("http://yyyZLtd.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new  MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/Inventory/99");
if (response.IsSuccessStatusCode) <- ERROR RETURNED

完整的错误消息......

  

{StatusCode:404,ReasonPhrase:&#39; Not Found&#39;,Version:1.1,Content:System.Net.Http.StreamContent,Headers:   {     日期:星期一,2016年5月2日14:54:08 GMT     服务器:Microsoft-IIS / 8.5     X-Powered-By:ASP.NET     内容长度:1245     内容类型:text / html   }}

我一定错过了什么。 Web Api的新功能,总是使用SOAP,这似乎更容易。

谢谢,任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

就在我准备退出的时候......我之前尝试过这个但没有成功,但这次它起作用了......

 

画了......感谢你的建议。

我完全开始了 - 成功是第四次尝试。最初,我试图从空模板创建一个WebApi项目,只添加WebApi。我最终决定使用Mvc和WebApi以及4.6的目标框架来使用空模板。我添加了与之前使用的相同的类和控制器,并且它起作用,至少在Get或Post上。模块改变了上面,给了我Put和Delete的能力。

我对我的Web进行了以下更改.Config ...

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
  <remove name="WebDAVModule" />
</modules>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
  <remove name="WebDAV"/>      
  <remove name="OPTIONSVerbHandler"/>
  <remove name="TRACEVerbHandler"/>
  <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*,GET,POST,PUT,DELETE" type="System.Web.Handlers.TransferRequestHandler"
    preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>

希望这有助于其他人。在让一切工作之前,我打开和关闭了4天。如果有人想要的话,非常乐意分享代码。