Chris Purves
Chris Purves

Reputation: 399

WCF Service works in VS debug mode, not when published to IIS

I have a site that includes a WCF Service (AJAX Enabled). Everything works when launched in debug mode in Visual Studio. When I publish the site to an IIS server, the WCF Service appears not be be available. I get a 404 error trying to load the javascript file produced by the web service.

Beginning of my code behind for web service file, 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
{

My 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>

In my default.aspx I have included:

    <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>

Using Visual Studio 2013, when I run the site in debug mode the page source includes:

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

I can browse that file and it includes the functions I added to the service.

If I publish the site on an IIS 8.5 server, the page source includes:

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

However, this returns a 404 error.

Upvotes: 0

Views: 1197

Answers (1)

Chris Purves
Chris Purves

Reputation: 399

I was able to find the solution. I needed to enable the WCF Services Features in Windows Features. The default installation for the server had 4/5 unchecked.

enter image description here

Upvotes: 1

Related Questions