37

当我在 Visual Studio 2012 中右键单击Eval.svc并在浏览器中查看时,我得到以下信息 -

找不到类型“EvalServiceLibary.Eval”,作为 ServiceHost 指令中的服务属性值提供,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。

当我从测试客户端运行 WCF 服务时,一切正常。

评估服务:

[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(服务合同)

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

Eval.svc标记:

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

任何想法为什么我会收到此错误?我搜索了谷歌并遇到了几页,但似乎没有任何效果。

谢谢!

4

15 回答 15

78

更改Eval.svc文件中的以下行:

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

至:

<%@ ServiceHost Language="C#" Debug="true" Service="EvalServiceLibary.EvalService" %>
于 2014-05-12T09:42:30.037 回答
39

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

于 2015-04-28T15:31:55.663 回答
19

面对这个确切的问题。当我更改标记中的 Service="Namespace.ServiceName" 标记(右键单击 xxxx.svc 并在 Visual Studio 中选择查看标记)以匹配我用于 xxxx.svc.cs 文件的命名空间时,问题解决了

于 2015-09-10T14:41:00.937 回答
11

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

于 2013-07-11T12:00:20.147 回答
6
  1. 创建 IIS 应用程序时,只有/binor/App_Code文件夹位于 IIS 应用程序的根目录中。所以只需记住将所有代码放在根目录/bin/App_code目录中(请参阅http://blogs.msdn.com/b/chrsmith/archive/2006/08/10/wcf-service-nesting-in-iis.aspx)。

  2. 确保服务名称和合约包含全名(例如namespace.ClassName),并且服务名称和接口与 web.config 中端点的服务标签和合约的名称属性相同。

于 2016-01-05T20:02:50.530 回答
4

我自己也遇到了这个问题,这个问题和网上的任何其他答案都没有解决我的问题。对我来说,这是一个奇怪的问题,虚拟目录是在另一个源代码控制服务器的不同分支上创建的(基本上,我们从 TFS 2010 升级到 2013)并且解决方案以某种方式记住了它的映射。

无论如何,我在服务项目的属性中再次单击了“创建虚拟目录”按钮。它给了我一条关于被映射到不同文件夹的消息,我想更新它。我点击是,这解决了这个问题。

于 2015-03-06T12:43:16.993 回答
4

右键单击解决方案资源管理器中的 .svc 文件,然后单击View Markup

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

更新您所指的服务参考。

于 2018-01-10T22:48:06.973 回答
3

我更改了服务的输出路径。它应该bin在服务项目的文件夹内。一旦我将输出路径放回bin,它就起作用了。

于 2015-06-26T19:16:47.767 回答
1

我有同样的问题。确保Factory在文件的属性中包含程序集名称.svc。如果您重命名了项目程序集名称,则可能需要清理 IIS 缓存。

于 2018-11-13T11:54:22.850 回答
0

仔细检查项目 .net 版本。使用不同 .net 版本相互引用的项目会导致问题。

于 2015-05-26T12:13:26.150 回答
0

就我而言,我对 iis 上的错误文件夹进行了“转换为应用程序”。我的应用程序设置在它应该在的子文件夹中。

于 2015-06-05T10:09:22.460 回答
0

我也有同样的问题。故意我的构建输出路径是“..\bin”,当我将构建输出路径设置为“\bin”时它对我有用。

于 2015-09-10T03:24:26.880 回答
0

当我将 Visual Studio 中的当前构建配置设置为除调试以外的其他设置时,我遇到了此错误。

于 2015-07-23T06:09:31.307 回答
0

这是一个老错误,但我今天在一个 Web 服务上遇到它,自从通过“New \ Project..”创建以来几乎没有改变过。

对我来说,这个问题是由IService.cs包含以下内容的“”文件引起的:

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

请注意,属性中的值在末尾Service包含“ ”。.svc

这不应该在那里。

删除这 4 个字符解决了这个问题。

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

请注意,您需要从 Visual Studio 外部打开此文件。

Visual StudioService1.cs在解决方案资源管理器中显示一个文件,但它只允许您更改Service1.svc.cs,而不是Service1.svc文件。

于 2015-08-13T11:40:42.737 回答
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.

于 2021-08-25T14:30:33.007 回答