36
votes

When I right click on Eval.svc within Visual Studio 2012 and view in browser, I get the following -

The type 'EvalServiceLibary.Eval', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

When I run the WCF service from the test client, all works fine.

Eval service:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class EvalService : IEvalService
{
    Dictionary<string, JobPhaseTimer> jobTimers = new Dictionary<string, JobPhaseTimer>();

    public void SubmitEntry(ENBO.Jobs.Job job, ENBO.Jobs.JobDetail jobDetail, ENBO.TimeLogs.TimeLog timeLog, ENBO.Users.User user, ENBO.Utilities.EntryType entryType, JobPhase jobPhase)
    {
        if (entryType == EntryType.Active)
        {
            JobPhaseTimer timer = new JobPhaseTimer();
            timer.UID = job.ID + "_" + jobPhase.ID;
            timer.JobID = job.ID;
            timer.JobDetailID = jobDetail.ID;
            timer.PhaseID = jobPhase.ID;
            timer.StartTime = DateTime.Now;
            timer.Stopwatch.Start();
            jobTimers.Add(timer.UID, timer);

            TimeLog log = new TimeLog();
            log.JobID = job.ID;
            log.PhaseID = jobPhase.ID;
            log.UserID = user.ID;
            log.DateEntry = DateTime.Now;
            log.EntryType = EntryType.Active;

            if (log.AddNewTimeLog())
            {
                //Do something
            }
        }
        else if (entryType == EntryType.Paused)
        {
            JobPhaseTimer timer = jobTimers[job.ID + "_" + jobPhase.ID];
            timer.Stopwatch.Stop();

            TimeLog log = new TimeLog();
            log.JobID = job.ID;
            log.PhaseID = jobPhase.ID;
            log.UserID = user.ID;
            log.DateEntry = DateTime.Now;
            log.EntryType = EntryType.Paused;

            if (log.AddNewTimeLog())
            {
                //Do something
            }
        }
    }
}

IEvalService.cs (Service Contract)

[ServiceContract]
public interface IEvalService
{
    [OperationContract]
    void SubmitEntry(Job job, JobDetail jobDetail, TimeLog timeLog, User user, EntryType entryType, JobPhase jobPhase);
}

Eval.svc markup :

<%@ ServiceHost Language="C#" Debug="true" Service="EvalServiceLibary.Eval" %>

Web.config :

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="EvalServiceLibary.EvalService">
        <endpoint address="" behaviorConfiguration="" binding="webHttpBinding"
      contract="EvalServiceLibary.IEvalService" />
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
      contract="EvalServiceLibary.IEvalService" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EvalServiceSite.EvalAspNetAjaxBehavior">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

Any ideas why I am getting this error? I have searched Google and come across a few pages but nothing seems to work.

Thanks!

14
is it a web project? What is the web.config like?Aliostad
Yes, a web project. I have added the web.config to the question. Cheersdynamicuser

14 Answers

76
votes

Change the following line in your Eval.svc file from:

<%@ ServiceHost Language="C#" Debug="true" Service="EvalServiceLibary.Eval" %> 

to:

<%@ ServiceHost Language="C#" Debug="true" Service="EvalServiceLibary.EvalService" %>
37
votes

Ensure that binary files are under "bin" subdirectory of your ".svc" file

18
votes

Faced this exact issue. The problem resolved when i changed the Service="Namespace.ServiceName" tag in the Markup (right click xxxx.svc and select View Markup in visual studio) to match the namespace i used for my xxxx.svc.cs file

11
votes

Turns out that the Eval.svc.cs needed its namespace changed to EvalServiceLibary, rather than EvalServiceSite.

6
votes
  1. When you create an IIS application only the /bin or /App_Code folder is in the root directory of the IIS app. So just remember put all the code in the root /bin or /App_code directory (see http://blogs.msdn.com/b/chrsmith/archive/2006/08/10/wcf-service-nesting-in-iis.aspx).

  2. Make sure that the service name and the contract contain full name(e.g namespace.ClassName), and the service name and interface is the same as the name attribute of the service tag and contract of endpoint in web.config.

4
votes

I just hit this issue myself, and neither this nor any of the other answers on the net solved my issue. For me it was a strange one whereby the virtual directory had been created on a different branch in another source control server (basically, we upgraded from TFS 2010 to 2013) and the solution somehow remembered it's mapping.

Anyway, I clicked the "Create Virtual Directory" button again, in the Properties of the Service project. It gave me a message about being mapped to a different folder and would I like to update it. I clicked yes, and that fixed the issue.

3
votes

I changed the output path of the service. it should be inside bin folder of the service project. Once I put the output path back to bin, it worked.

3
votes

Right click on the .svc file in Solution Explorer and click View Markup

 <%@ ServiceHost Language="C#" Debug="true" 
     Service="MyService.**GetHistoryInfo**" 
     CodeBehind="GetHistoryInfo.svc.cs" %>

Update the service reference where you are referring to.

1
votes

I had the same problem. Make sure you include assembly name in Factory property in your .svc file. Maybe you need to clean IIS cache if you had renamed project assembly name.

0
votes

Double check projects .net versions. Projects that referenced each other with different .net versions causes problems.

0
votes

In my case I did a "Convert to application" to the wrong folder on iis. My application was set in a subfolder of where it should have been.

0
votes

I had this error when I had the current build configuration in Visual Studio set to something other than Debug.

0
votes

This is an old bug, but I encountered it today on a web service which had barely been altered since being created via "New \ Project.."

For me, this issue was caused by the "IService.cs" file containing the following:

<%@ ServiceHost Language="C#" Debug="true" Service="JSONWebService.Service1.svc" CodeBehind="Service1.svc.cs" %>

Notice the value in the Service attribute contains ".svc" at the end.

This shouldn't be there.

Removing those 4 characters resolved this issue.

<%@ ServiceHost Language="C#" Debug="true" Service="JSONWebService.Service1" CodeBehind="Service1.svc.cs" %>

Note that you need to open this file from outside of Visual Studio.

Visual Studio shows one file, Service1.cs in the Solution Explorer, but that only lets you alter Service1.svc.cs, not the Service1.svc file.

0
votes

I also had same problem. Purposely my build output path was "..\bin" and it works for me when I set the build output path as "\bin".