0

I'm creating a WCF service and running it locally in VS.NET 2013. I can navigate to the svc file fine, but when I try to call one of the methods, I get a 404 response. I appreciate any ideas you all have.

Here's the interface file:

public interface ITechManager
{
    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    List<Tech> GetTechListings();
    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Tech GetTechDetails(int id);
}

Here's the .svc file:

public class TechManager : ITechManager
{
    public List<Tech> GetTechListings()
    {
        List<Tech> techs = GetTech(0);
        return techs;
    }

    public Tech GetTechDetails(int id)
    {
        List<Tech> techs = GetTech(id);
        if (techs.Count > 0)
        {
            return techs[0];
        }
        else
        {
            return new Tech();
        }
    }

    private List<Tech> GetTech(int id)
    {...}

Here's the web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
</system.web>
<system.serviceModel>
<bindings>
  <webHttpBinding>
    <binding>
      <security mode="None"></security>
    </binding>
  </webHttpBinding>
</bindings>
<services>
  <service name="testing.TechManager" behaviorConfiguration="webBehavior">
    <endpoint address="TechManager.svc" binding="webHttpBinding" contract="testing.ITechManager"></endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="webBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
  multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>

Here's the Javascript I'm using to call the methods:

    <script type="text/javascript">
    function GetListing() {
        $.ajax({
            type: "POST",
            url: "TechManager.svc/GetTechListings",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                var itemRow = "< table >";
                $.each(data, function (index, item) {
                    itemRow += "<tr><td>" + item.ID + "</td><td>" + item.Title + "</td></tr>";
                });
                itemRow += "</table>";

                $("#items").html(itemRow);
            }
        });

    }
    function GetDetails() {
        $.ajax({
            type: "POST",
            url: "TechManager.svc/GetTechDetails",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: "{ID: 321}",
            success: function (data) {
                var itemRow = "< table >";
                $.each(data, function (index, item) {
                    itemRow += "<tr><td>" + item.ID + "</td><td>" + item.Title + "</td></tr>";
                });
                itemRow += "</table>";

                $("#items").html(itemRow);
            }
        });

    }
</script>
Andre
  • 181
  • 2
  • 11
  • `http://localhost:1234/TechManager.svc/GetTechDetails` ? Is your wcf service running on the same port as your JS application? – Max Sorin Apr 21 '16 at 16:36
  • Yes it is. http://localhost:22346/TechManager.svc/GetTechListings returns a 404 while I browse to the Javascript mentioned above in an HTML page using http://localhost:22346/test.html – Andre Apr 21 '16 at 16:49
  • See [HTTP 404 when accessing .svc file in IIS](http://stackoverflow.com/questions/2609377/http-404-when-accessing-svc-file-in-iis) – Petar Vučetin Apr 21 '16 at 17:30
  • I tried the suggestions on "HTTP 404 when accessing .svc file in IIS" but still get the same problem. I can access localhost:22346/TechManager.svc without a problem too. – Andre Apr 21 '16 at 18:37

0 Answers0