0

我有一个包含 WCF 服务(启用 AJAX)的站点。在 Visual Studio 中以调试模式启动时一切正常。当我将站点发布到 IIS 服务器时,WCF 服务似乎不可用。尝试加载 Web 服务生成的 javascript 文件时出现 404 错误。

我的 Web 服务文件 SqlAjax.cs 代码的开头:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Script.Serialization;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SqlAjax
{

我的 web.config:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
  <connectionStrings>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1">
      <assemblies>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5.1"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="SqlAjaxAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <services>
      <service name="SqlAjax">
        <endpoint address="" behaviorConfiguration="SqlAjaxAspNetAjaxBehavior" binding="webHttpBinding" contract="SqlAjax"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>

在我的 default.aspx 中,我包括:

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="True">
        <Scripts>
            <asp:ScriptReference Path="~/Scripts/jquery-2.1.1.min.js" />
            <asp:ScriptReference Path="~/Scripts/jquery-ui.min-1.11.1.js" />
        </Scripts>
        <Services>
            <asp:ServiceReference Path="~/WebServices/SqlAjax.svc" />
        </Services>
    </asp:ScriptManager>

使用 Visual Studio 2013,当我在调试模式下运行站点时,页面源包括:

<script src="WebServices/SqlAjax.svc/jsdebug" type="text/javascript"></script>

我可以浏览该文件,它包含我添加到服务中的功能。

如果我在 IIS 8.5 服务器上发布站点,则页面源包括:

<script src="WebServices/SqlAjax.svc/js" type="text/javascript"></script>

但是,这会返回 404 错误。

4

1 回答 1

1

我能够找到解决方案。我需要在 Windows 功能中启用 WCF 服务功能。服务器的默认安装未选中 4/5。

在此处输入图像描述

于 2014-10-09T17:44:01.917 回答