问题描述
我试着去创造我的第一个WCF RESTful服务。
在VS2010我打开weddingservice.svc,然后按F5键。浏览器中打开
但是,这是我得到的错误:
在'/'应用程序的服务器错误。类型'RestService.weddingservice,作为服务提供的属性在ServiceHost的指令值,或在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations提供找不到。说明:执行当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。异常详细信息:System.InvalidOperationException:类型RestService.weddingservice,作为服务提供的属性在ServiceHost的指令值,或在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations提供找不到。源错误:当前Web请求的执行过程中生成了未处理的异常。有关异常的来源和位置信息可以使用异常堆栈跟踪下面确定。堆栈跟踪:
[出现InvalidOperationException:类型'RestService.weddingservice',因为在ServiceHost的指令中的服务属性值提供的,或在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations找不到提供。]
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(字符串constructorString,乌里[] baseAddresses)51530
System.ServiceModel.HostingManager.CreateService(字符串normalizedVirtualPath)1461
System.ServiceModel.HostingManager.ActivateService(字符串normalizedVirtualPath)+44
System.ServiceModel.HostingManager.EnsureServiceAvailable(字符串normalizedVirtualPath)651[ServiceActivationException:服务'/weddingservice.svc'不能被激活由于编译期间的异常。异常消息为:类型'RestService.weddingservice,作为服务提供的属性在ServiceHost的指令值,或在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations找不到提供..]
System.Runtime.AsyncResult.End(IAsyncResult的结果)688590
System.ServiceModel.Activation.HostedHtt prequestAsyncResult.End(IAsyncResult的结果)+190
System.ServiceModel.Activation.HostedHtt prequestAsyncResult.ExecuteSynchronous(HttpApplication的背景下,字符串routeServiceVirtualPath,布尔flowContext,布尔ensureWFService)+234
System.ServiceModel.Activation.HttpModule.ProcessRequest(对象发件人,EventArgs的发送)+359
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+148
System.Web.HttpApplication.ExecuteStep(IExecutionStep一步,布尔和放大器; completedSynchronously)+75版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272
下面我code,我希望有人能够看到什么即时通讯做错了。难道我没有使用正确的URI?我错过了什么?
weddingservice.svc
<%@ ServiceHost的语言=VB调试=真正的服务=RestService.weddingservicecodeBehind =weddingservice.svc.vb%GT;
Iweddingservice.vb
进口System.ServiceModel
进口的System.Web
进口System.IO
进口System.Runtime.Remoting.Activation
进口System.Collections.Generic命名空间RestService
&所述;的ServiceContract()>
公共接口Iweddingservice &所述; OperationContract的()> _
< Web.WebGet(UriTemplate:=工作/ {name}的)> _
功能DoJob(名称作为字符串)作为字符串结束接口
最终命名空间
weddingservice.svc.vb
进口System.ServiceModel
进口System.ServiceModel.Web
进口System.IO
进口System.ServiceModel.Activation
进口System.Web.Script.Serialization
进口System.Collections.Generic
进口的System.Xml
进口System.Net命名空间RestService
公共类weddingservice
实现Iweddingservice 公共职能DoJob(名称作为字符串)作为字符串实现Iweddingservice.DoJob
返回的String.Format(你好,{0},名称)
结束功能
末级
最终命名空间
的web.config
< system.serviceModel>
< serviceHostingEnvironment multipleSiteBindingsEnabled =真/>
<服务和GT;
<服务名称=weddingservice>
<端点绑定=的WebHttpBinding合同=RestService.IweddingservicebehaviorConfiguration =webHttp/>
< /服务>
< /服务>
<&行为GT;
< serviceBehaviors>
<行为NAME =>
< serviceMetadata httpGetEnabled =真/>
< serviceDebug includeExceptionDetailInFaults =FALSE/>
< /行为>
< / serviceBehaviors>
< endpointBehaviors>
<行为NAME =webHttp>
< webHttp />
< /行为>
< / endpointBehaviors>
< /行为>
< /system.serviceModel>
将
< serviceDebug includeExceptionDetailInFaults =FALSE/>
到
< serviceDebug includeExceptionDetailInFaults =真/>
为了获得更多的细节。
和尝试再次运行过程
Im trying to create my first WCF restful service. In VS2010 I open weddingservice.svc and then hit F5. A browser opens to http://localhost:50043/weddingservice.svcBut there, this is the error I get:
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
Below my code, I hope anyone is able to see what Im doing wrong. Am I not using the correct URI? What did I miss?
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>
Set the
<serviceDebug includeExceptionDetailInFaults="false" />
to
<serviceDebug includeExceptionDetailInFaults="true" />
in order to get more details
and try to run the process again
这篇关于类型'RestService.weddingservice',因为在ServiceHost的指令中的服务属性值提供找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!