C# WCF 服务,作为服务属性值提供的类型……找不到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17591972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:57:28  来源:igfitidea点击:

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

c#wcfwcf-binding

提问by dynamicuser

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

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

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.

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

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

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

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)

IEvalService.cs(服务合约)

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

Eval.svcmarkup :

Eval.svc标记:

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

Web.config:

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!

谢谢!

采纳答案by dynamicuser

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

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

回答by user3578181

Change the following line in your Eval.svcfile from:

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

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

to:

到:

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

回答by Detail

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.

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

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.

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

回答by vasek

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

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

回答by Mehmet

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

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

回答by Navy Seal

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.

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

回答by Gokul

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

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

回答by BineG

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

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

回答by Mike Gledhill

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

这是一个旧错误,但我今天在一个 Web 服务上遇到了它,该服务自通过“新建\项目..”创建以来几乎没有改变过。

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

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

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

Notice the value in the Serviceattribute contains ".svc" at the end.

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

This shouldn't be there.

这不应该在那里。

Removing those 4 characters resolved this issue.

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

<%@ 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 外部打开此文件。

Visual Studio shows one file, Service1.csin the Solution Explorer, but that only lets you alter Service1.svc.cs, notthe Service1.svcfile.

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

回答by K.Kirivarnan

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

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