38

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!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
dynamicuser
  • 1,522
  • 3
  • 24
  • 52

15 Answers15

81

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" %>
songyuanyao
  • 169,198
  • 16
  • 310
  • 405
user3578181
  • 1,896
  • 2
  • 17
  • 12
  • 1
    This should be on my 'Strange WCF Service Errors List' or something. – Gerben Limburg Jan 13 '15 at 21:09
  • 10
    Worked! Just to add, if you can't find the specified markup - right click on the .svc file in Solution Explorer and click "View Markup". Otherwise, if you open it, it opens the code file. – Arman Bimatov May 17 '15 at 07:35
  • 1
    OMG! I looked everywhere for this after I changed the name of the service in a tutorial from service1 to something else. A freakin' right-click on the .svc file saved me hours of hair pulling!!! – MC9000 Jun 13 '15 at 07:01
  • 1
    I'm happy that it worked for you guys. Cheers - Ali Rahimy – user3578181 Feb 29 '16 at 22:59
  • I missed this too. Hey, is the damn cable plugged in? :( – BeanFlicker Mar 27 '16 at 15:14
  • 2
    This happened to me when I changed the `namespace` under my project after the .svc was already created. It updated everywhere except in the markup. – Bensonius Aug 23 '17 at 23:15
  • They really should automatically rename the service in the markup since when you rename the .svc file it renames everywhere else ... – eracer9 Jun 07 '21 at 14:41
41

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

vasek
  • 2,759
  • 1
  • 26
  • 30
19

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

WonderYearsKid
  • 310
  • 2
  • 4
11

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

Zukunft
  • 17
  • 1
  • 5
dynamicuser
  • 1,522
  • 3
  • 24
  • 52
6
  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.

Scott Baker
  • 10,013
  • 17
  • 56
  • 102
  • second point helped me, service name includes namespace name but not class name so completed service name by **Namespace.ClassName** – Prakash Joshi Feb 15 '16 at 11:41
  • 1
    I got this error when debug on Test Client, somehow have to remove the \bin\debug to just \bin for it to works. Why is it so? – TPG Aug 23 '19 at 06:28
5

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.

Detail
  • 785
  • 9
  • 23
4

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.

Kcoder
  • 3,422
  • 4
  • 37
  • 56
Joe
  • 509
  • 4
  • 11
  • This did it for me. Initial cause was the failure of the 'rename' operation on the default service name 'Service1'. – Rik Bradley Mar 31 '20 at 09:32
3

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.

Atanu Roy
  • 1,384
  • 2
  • 17
  • 29
Gokul
  • 31
  • 1
1

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.

Jalal
  • 6,594
  • 9
  • 63
  • 100
0

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

Mehmet
  • 1
  • 4
0

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.

João Serra
  • 379
  • 1
  • 5
  • 20
0

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

BineG
  • 365
  • 3
  • 9
0

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.

Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159
0

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

K.Kirivarnan
  • 828
  • 9
  • 15
0

We've just had this issue, and it was none of the answers already given. It also had some notable identifying features, which were different than specified in the question, so this answer relates to these circumstances:

  1. It occurred on a load-balanced web farm.
  2. The servers were replicated.
  3. The service worked fine on the "primary" server on the farm (demonstrated by using a browser on that server to go to the service's URL) but not on the other server on the farm (demonstrated the same way).

The EventViewer Application log on the server where it failed had this error (which matches the question, I'm just giving the full exception message):

System.ServiceModel.ServiceActivationException: The service '/redactedService.svc' cannot be activated due to an exception during compilation. The exception message is: The type 'redactedService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.. ---> System.InvalidOperationException: The type 'redactedService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Usually we get this issue the first time that we deploy a new IIS-hosted WCF service. On the non-primary servers, in "IIS Manager", the App Pool has a red cross on it, and you can fix it by double-clicking the AppPool and then pressing OK (without changing anything). You don't even need to recycle the AppPool.

However, we've just had this occur when adding a new instance of a service which uses a pre-existing AppPool. And in that scenario, the other things using the same AppPool are still working, it's only the new one which is failing. In that case, there is no "red cross" on the AppPool, but the same solution still works.

Richardissimo
  • 5,596
  • 2
  • 18
  • 36