简体   繁体   English

调试WCF Web Api REST服务时出现问题

[英]Problems debugging WCF Web Api REST service

So I have created a REST service based on WCF Web API. 因此,我已经基于WCF Web API创建了REST服务。 It runs fine on my local IIS. 它在我的本地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. 在我的global.asax.cs中,将路线“ MyRoute”映射到类MyHandler。 So whenever I go to http://localhost/MyApplication/MyRoute/MyResource I get a valid response. 因此,每当我访问http:// localhost / MyApplication / MyRoute / MyResource时,我都会收到有效的响应。

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") 但是,如果我在IE中打开http:// localhost / MyApplication / MyRoute / MyResource ,则在部署后在外部服务器上,我会收到“ Internet Explorer无法显示网页”(FF =“连接已重置-与服务器的连接在重置时页面正在加载”)

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". 如果输入无效的资源名称: http:// localhost / MyApplication / MyRoute / adfasdf,我在外部服务器上获得的结果与在本地获得的结果相同:“找不到端点”。

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. 此外,我尝试从/ MyRoute / MyResource映射到的MyHandler的方法中删除所有逻辑,以查看该代码中有什么导致请求失败,但结果仍然存在。

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: 我通过将其包含在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? 服务器上是否有一个配置文件来定义要加载的模块,因为这显然在本地IIS和外部IIS之间有所不同?

... And I still don't know where the logs are. ...而且我仍然不知道日志在哪里。

When hosting on IIS, Web API uses the same URL routing module as ASP.NET (MVC) to select the endpoint. 在IIS上托管时,Web API使用与ASP.NET(MVC)相同的URL路由模块来选择终结点​​。 If you're self hosting, it doesn't have to. 如果您是自托管的,则不必这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM