【问题标题】:The type 'RestService.weddingservice', provided as the Service attribute value in the ServiceHost directive could not be found找不到作为 ServiceHost 指令中的服务属性值提供的类型“RestService.weddingservice”
【发布时间】:2012-03-04 17:35:30
【问题描述】:

我正在尝试创建我的第一个 WCF 宁静服务。 在VS2010中,我打开weddingservice.svc,然后按F5。浏览器打开到http://localhost:50043/weddingservice.svc 但是,这是我得到的错误:

Server Error in '/' Application.

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The type 'RestService.weddingservice', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[InvalidOperationException: The type 'RestService.weddingservice', 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.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +51530
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1461
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +651

[ServiceActivationException: The service '/weddingservice.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'RestService.weddingservice', 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.Runtime.AsyncResult.End(IAsyncResult result) +688590
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234
   System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +359
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

在我的代码下面,我希望任何人都能够看到我做错了什么。我没有使用正确的 URI 吗?我错过了什么?

weddingservice.svc

<%@ ServiceHost Language="VB" Debug="true" Service="RestService.weddingservice" CodeBehind="weddingservice.svc.vb" %>

Iweddingservice.vb

Imports System.ServiceModel
Imports System.Web
Imports System.IO
Imports System.Runtime.Remoting.Activation
Imports System.Collections.Generic

Namespace RestService
<ServiceContract()>
Public Interface Iweddingservice

    <OperationContract()> _
<Web.WebGet(UriTemplate:="job/{name}")> _
    Function DoJob(name As String) As String

End Interface
End Namespace

weddingservice.svc.vb

Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports System.IO
Imports System.ServiceModel.Activation
Imports System.Web.Script.Serialization
Imports System.Collections.Generic
Imports System.Xml
Imports System.Net

Namespace RestService
    Public Class weddingservice
        Implements Iweddingservice

        Public Function DoJob(name As String) As String Implements Iweddingservice.DoJob
            Return String.Format("Hello, {0}", name)
        End Function
    End Class
End Namespace

web.config

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  <services>
    <service name="weddingservice">
      <endpoint binding="webHttpBinding" contract="RestService.Iweddingservice" behaviorConfiguration="webHttp"/>
    </service>
  </services>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webHttp">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>  

【问题讨论】:

    标签: asp.net wcf


    【解决方案1】:

    设置

    <serviceDebug includeExceptionDetailInFaults="false" />
    

    <serviceDebug includeExceptionDetailInFaults="true" />
    

    为了了解更多详情

    并尝试再次运行该过程

    【讨论】:

    • 我按照你说的做了,我已经更新了错误...希望你能看到新的东西:)
    • 1.单击工具菜单,然后单击“WCF 服务配置编辑器”。 2. 编辑器打开后,关闭它。 3. 现在右键单击 Web.config 文件,然后选择“编辑 WCF 配置” 4. 在服务文件夹下,选择婚礼服务,然后在右侧窗格中单击名称属性的值。 5. 按 ... 按钮,然后导航到 Bin 目录并双击您的程序集 dll。 6. 选择程序集后,选择(2* 单击)实现 Iweddingservice 接口的类(weddingservice 类) 7. 选择后,选择 File |保存,然后尝试
    • 这有帮助!我必须在 RestService 命名空间之前添加一个命名空间!现在可以了!伟大的!谢谢!
    【解决方案2】:

    我最近重新配置了我的项目并遇到了这个错误。

    这是一个设置错误,发布网站时我的服务 DLL 没有放在正确的目录中。

    【讨论】:

      【解决方案3】:

      请从以下位置更改您的服务元素:

      <service name="weddingservice">
      

      到:

      <service name="RestService.weddingservice">
      

      这应该可以解决您的问题

      【讨论】:

        【解决方案4】:

        当我手动将 Bin 文件夹和 obj 文件夹添加到文件夹路径中时,我的问题得到了解决。我现在可以完美访问它了。

        【讨论】:

        • 你添加到哪个文件夹路径?
        【解决方案5】:

        我遇到了同样的问题。只需删除 bin 和 obj 文件夹并重建即可解决问题。

        【讨论】:

          【解决方案6】:

          我的项目将 dll 构建到 bin 目录下的文件夹中以匹配配置名称,因此如果项目名称为 DemoWCF 且配置为 Debug,则 dll 将在此处:

          /bin/Debug/DemoWCF.dll
          

          当我从输出路径中删除 Debug/ 并将 dll 构建到此处时:

          /bin/DemoWCF.dll 
          

          一切都按预期启动。

          这是在输出路径中项目属性的构建选项卡下配置的

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-07-09
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-07-14
            相关资源
            最近更新 更多