调试 WCF Web Api REST 服务时出现问题
所以我创建了一个基于WCF Web API的REST服务。它在我的本地 IIS 上运行良好。但是当我将它部署到外部服务器时它不起作用。
在我的 global.asax.cs 中,我将路由“MyRoute”映射到 MyHandler 类。因此,每当我访问 http://localhost/MyApplication/MyRoute/MyResource 时,我都会得到有效的响应。
但是,在部署后的外部服务器上,如果我在 IE 中打开 http://localhost/MyApplication/MyRoute/MyResource我收到“Internet Explorere 无法显示网页”(FF =“连接已重置 - 加载页面时重置了与服务器的连接”)
如果我输入无效的资源名称:http://localhost/MyApplication/MyRoute/adfasdf 我在外部服务器上得到的结果与在本地得到的结果相同: “未找到端点”。
此外,我尝试从 /MyRoute/MyResource 映射到的 MyHandler 中的方法中删除所有逻辑,以查看该代码中是否有某些内容导致请求失败,但结果仍然存在。
我最好的猜测是,问题出在路线映射上。
我非常感谢您在我遇到的这个特定情况下提供的帮助,或者更一般地说如何调试它。令人沮丧的是我什至不知道在哪里可以找到错误日志。我查看了事件查看器,但找不到任何内容,也不知道在哪里查看更多内容。
如果有帮助的话,我很乐意发布一些代码。
编辑:
好的,所以我解决了这个问题。这是一个路由问题。我通过将其包含在 web.config 中解决了这个问题:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
我仍然不介意了解这些模块背后的机制。它们在哪里定义的?服务器是否有一个配置文件定义了加载哪些模块,因为显然这在我的本地 IIS 和外部 IIS 之间有所不同?
...而且我仍然不知道日志在哪里。
So I have created a REST service based on WCF Web API. It runs fine on my local IIS. But when I deploy it to an external server it doesnt work.
In my global.asax.cs I map a route "MyRoute" to a class MyHandler. So whenever I go to http://localhost/MyApplication/MyRoute/MyResource I get a valid response.
However on the external server after deployment if I open http://localhost/MyApplication/MyRoute/MyResource in IE I get "Internet Explorere cannot display the webpage" (FF = "The connection was resset - The connection to the server was reset while the page was loading")
If I enter an invalid resource name: http://localhost/MyApplication/MyRoute/adfasdf I get the same result on the external server as I get locally: "Endpoint not found".
Furthermore, I have tried removing all logic from the method in MyHandler that /MyRoute/MyResource is mapped to, to see there was something in that code that was causing the request to fail, but the result remains.
My best guess is that the issue somehow is with the route mapping.
I'd be really thankful for help either in this specific case I am having, or more generally on how to debug this. One frustration is that I am not even aware on where I can find error logs. I have looked in the event viewer, but can't find anything and don't know where to look more.
I'd be glad to post some code if that would help.
edit:
Ok, So I solved the issue. It was a routing thing. I solved it by including this in the web.config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule" />
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
I still wouldn't mind understanding the mechanics behind these modules. Where are they defined? Is there a config file for the server defines which modules are loaded since apparently this differs somehow between my local IIS and the external one?
... And I still don't know where the logs are.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当托管在 IIS 上时,Web API 使用与 ASP.NET (MVC) 相同的 URL 路由模块来选择端点。如果您是自托管,则不必这样做。
When hosting on IIS, Web API uses the same URL routing module as ASP.NET (MVC) to select the endpoint. If you're self hosting, it doesn't have to.