【问题标题】:Ajax-Enabled WCF Service return error 500 when hosted on IIS当托管在 IIS 上时,启用 Ajax 的 WCF 服务返回错误 500
【发布时间】:2016-03-10 15:17:35
【问题描述】:

我正在尝试使用我的 Web 应用程序设置启用 Ajax 的 WCF 服务。我可以在 Visual Studio 中很好地使用它,但是当我发布网站并将其托管在 IIS 上时,似乎无法正确管理该服务。

例如:

当通过 Visual Studio 托管网站时(我假设是 cassini),我在我的本地主机 localhost:62006/WebServices/SaphirExternService.svc/jsdebug 上生成了一个 Javascript 文件,它允许我从 javascript 调用 web 服务的方法。

但是在生产环境中,当我收到/WebServices/SaphirExternService.svc/js 时,出现了服务器 500 错误。实际上我什至不能浏览到url/WebServices/SaphirExternService.svc(相同的500)。

错误如下(大致翻译):

could not load the type 'System.ServiceModel.Activation.HttpHandler' from the assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

MyService.svc 包含:

<%@ ServiceHost Language="C#" 
Debug="true" Service="WebApplication.WebServices.SaphirExternService" 
Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"
CodeBehind="SaphirExternService.svc.cs" %>

服务在 aspx 中声明如下:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
    <Services>
        <asp:ServiceReference Path="~/WebServices/SaphirExternService.svc" />
    </Services>
</asp:ScriptManager>

并在 javascript 中调用如下:

var service = new WebServices.SaphirExternService();
service.DoWork("test", DoWorkSuccess, null, null);

最后是 Web.config:

<services>
  <service name="WebApplication.WebServices.SaphirExternService">
    <endpoint address="" behaviorConfiguration="WebApplication.WebServices.SaphirExternServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="WebApplication.WebServices.SaphirExternService" />
  </service>
</services>

<behaviors>
  <endpointBehaviors>
    <behavior name="WebApplication.WebServices.SaphirExternServiceAspNetAjaxBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
</behaviors>

这在 Visual Studio 本身上运行良好,但是在 IIS 上发布和托管时不再运行(因为未生成 /js 文件,因此未定义 SaphirExternService)。我尝试使用多个端点配置(如bindingConfiguration 属性)无济于事。我错过了什么?

【问题讨论】:

    标签: asp.net web-services wcf iis


    【解决方案1】:

    找到我的问题的解决方案,以防有人需要它以供将来参考。 svc 文件未在 IIS 中正确映射。我删除了 Handler Mappings 中的所有 *.svc 相关配置。然后分两步:

    1. 添加了新的 Mime 类型:
      • 扩展名: .svc
      • MIME 类型: application/octet-stream
    2. 在处理程序映射中 > 添加了一个新的托管代码处理程序:
      • 请求路径: *.svc
      • 类型: System.ServiceModel.Activation.HttpHandler
      • 名称: svc-Integrated

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-11
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 2013-08-10
      • 2012-07-06
      • 1970-01-01
      相关资源
      最近更新 更多