我有一个包含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错误。
答案 0 :(得分:1)
我能够找到解决方案。我需要在Windows功能中启用WCF服务功能。服务器的默认安装未选中4/5。