简体   繁体   中英

WCF Service, the type provided as the service attribute values…could not be found

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!

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

确保二进制文件位于“ .svc”文件的“ bin”子目录下

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

事实证明,Eval.svc.cs需要将其命名空间更改为EvalServiceLibary,而不是EvalServiceSite。

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.

  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(eg 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.

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.

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.

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.

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

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.

当我将Visual Studio中的当前构建配置设置为除Debug以外的其他内容时,出现了此错误。

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

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 '/ redacted Service.svc' cannot be activated due to an exception during compilation. The exception message is: The type ' redacted Service', 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 ' redacted Service', 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.

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.

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