简体   繁体   中英

WCF Problem Encountered: HTTP Error 404.0 - Not Found

The Problem

I am attempting to create a Rest service using WCF. I have created a WCF class in my call stack namespace called "Coronado.HUB" as shown below. When I make an http request to the service I get a 404 error.

The Source Code

using Coronado.HUB.Model;
using Coronado.HUB.Service;
using System;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace Coronado.HUB
{
    /// <summary>
    /// Returns Driver By ID
    /// </summary>
    [ServiceContract]
    public interface IDriverService
    {
        [OperationContract]
        [WebGet]
        Driver GetDriverById(Guid id);
    }

    /// <summary>
    /// Returns Driver Object By ID
    /// </summary>
    public class DriverService : IDriverService
    {
        public Driver GetDriverById(Guid id)
        {
            return DriverServiceProvider.Instance.GetDriverById(id);
        }
    }
}

Accordingly, in my ASP.NET project, I have added the following DriverService.svc file with the following reference

<%@ ServiceHost Service="Coronado.HUB.DriverService" %>

The Configuration

Finally, I added the following configuration to my web.config

<system.serviceModel>
    <services>
     <service name="Coronado.HUB.DriverService">
        <endpoint address="" binding="webHttpBinding" contract="Coronado.HUB.IDriverService" behaviorConfiguration="RestService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/XXX/DriverService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="RestService">
          <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

I have been trying to resolve this issue for a day and a half and I cannot get it to work. I would be grateful if someone could show me where I have gone wrong. Thank you for your time and consideration.

-- Update --

The URL I am trying to resolve is as follows

http://localhost/XXX/DriverService.svc/GetDriverById?id=F200A17F-9E03-41EB-90FB-01B8665246BB

The problem I encountered was caused because WCF was not registered with IIS. It is my understanding, pre .Net 4.0 - this is done via the command line. In my case, I used Programs & Features. This cleared up the problem

For additional information ref: IIS 7 not recognizing svc file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM