【问题标题】:System.NullReferenceException for .NET service running on windows server IIS but works locally when running in Visual Studio IIS ExpressSystem.NullReferenceException 用于在 Windows 服务器 IIS 上运行但在 Visual Studio IIS Express 中运行时在本地运行的 .NET 服务
【发布时间】:2020-05-28 15:02:56
【问题描述】:

我有一个继承的 .NET 项目,在 Windows Server IIS 上运行时,我无法让服务正确返回。

异常类型是System.NullReferenceException

堆栈跟踪是at Integra.HLX.SB.Web.WS_Reps..ctor() at CreateIntegra.HLX.SB.Web.WS_Reps() at System.ServiceModel.InstanceContext.GetServiceInstance(Message message) at System.ServiceModel.Dispatcher.InstanceBehavior.EnsureServiceInstance(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

当我尝试 POST 到服务的端点时会引发此错误。我假设我在 web.config 中遗漏了一些东西,以允许它在 Windows Server 上的 IIS 上工作,或者可能在 Windows Server 上的 IIS 中遗漏了功能设置。

这里是相关的 web.config 设置...

<system.serviceModel> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <bindings> <webHttpBinding> <binding name="binding1"> <security mode="Transport" /> </binding> </webHttpBinding> </bindings> <behaviors> <endpointBehaviors> <behavior name="Integra.HLX.SB.Web.WS_RepsAspNetAjaxBehavior"> <enableWebScript /> </behavior> <behavior name="Integra.HLX.SB.Web.WS_ClientContactsAspNetAjaxBehavior"> <enableWebScript /> </behavior> <behavior name="Integra.HLX.SB.Web.WS_ContactUniverseNameAddressesAspNetAjaxBehavior"> <enableWebScript /> </behavior> <behavior name="Integra.HLX.SB.Web.WS_UsersAspNetAjaxBehavior"> <enableWebScript /> </behavior> <behavior name="jsonBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="RESTbehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> <behavior> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <services> <service name="Integra.HLX.SB.Web.WS_Reps"> <endpoint address="" behaviorConfiguration="Integra.HLX.SB.Web.WS_RepsAspNetAjaxBehavior" bindingConfiguration="binding1" binding="webHttpBinding" contract="Integra.HLX.SB.Web.WS_Reps" /> </service> <service name="Integra.HLX.SB.Web.WS_ClientContacts"> <endpoint address="" behaviorConfiguration="Integra.HLX.SB.Web.WS_ClientContactsAspNetAjaxBehavior" bindingConfiguration="binding1" binding="webHttpBinding" contract="Integra.HLX.SB.Web.WS_ClientContacts" /> </service> <service name="Integra.HLX.SB.Web.WS_ContactUniverseNameAddresses"> <endpoint address="" behaviorConfiguration="Integra.HLX.SB.Web.WS_ContactUniverseNameAddressesAspNetAjaxBehavior" bindingConfiguration="binding1" binding="webHttpBinding" contract="Integra.HLX.SB.Web.WS_ContactUniverseNameAddresses" /> </service> <service name="Integra.HLX.SB.Web.WS_Users"> <endpoint address="" behaviorConfiguration="Integra.HLX.SB.Web.WS_UsersAspNetAjaxBehavior" bindingConfiguration="binding1" binding="webHttpBinding" contract="Integra.HLX.SB.Web.WS_Users" /> </service> <service name="Integra.HLX.SB.Web.WS_SpeakerDataFeed" behaviorConfiguration="RESTbehavior"> <endpoint address="" bindingConfiguration="binding1" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="Integra.HLX.SB.Web.IWS_SpeakerDataFeed" /> </service> <service name="Integra.HLX.SB.Web.WS_DashboardDataFeed" behaviorConfiguration="RESTbehavior"> <endpoint address="" bindingConfiguration="binding1" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="Integra.HLX.SB.Web.IWS_DashboardDataFeed" /> </service> </services> </system.serviceModel>

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 当异常清楚地给你调用堆栈时,我想知道是什么阻止你从那里调试。你必须更具体并分享更多细节。差别太多了,blog.lextudio.com/… 所以你不能让别人帮你猜。
  • 我尝试使用远程调试,但我无法在服务代码中添加断点(我相信它会抱怨未定义符号)。我能够在我的 Web 应用程序源代码中插入断点,并且在使用远程调试时这些断点确实会受到影响。
  • @LexLi:感谢您花时间研究这个问题,但正如我上面所指出的,我可以远程调试。如果我在调试模式下构建我的应用程序,该模式构建所有 .PDB 文件,并将其部署到我的 Windows 服务器,我能够成功调试我的 Web 应用程序源,但我无法调试存在于 App_Code 中的服务代码项目目录。
  • 我修好了。显然,web.config 缺少这一行,&lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt; 我通过检查 Windows 事件查看器日志找到了更多信息,并发现了这一关键信息The service cannot be activated because it requires ASP.NET compatibility. ,它为我指明了正确的方向。只希望原始异常有更多相关信息。

标签: c# asp.net iis


【解决方案1】:

我能够回答我自己的问题。在这种情况下,我的解决方法是生产服务器上的 web.config 缺少 &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt;

我通过查看 Windows 事件查看器日志了解了更多信息,并找到了这一关键信息The service cannot be activated because it requires ASP.NET compatibility.

将上述行插入web.config并重新启动AppPool和服务器后,服务开始正常工作。我希望这对将来的任何人都有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-10
    • 2017-04-09
    • 2020-03-24
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    相关资源
    最近更新 更多