积极答复者
引用wcf服务时出错

问题
-
引用wcf服务时报错。
下载“http://localhost:1051/Service.svc”时出错。
请求失败,错误信息为:
--
<html>
<head>
<title>无法找到 ServiceHost 指令中作为服务属性值提供的类型“MySqlForNet.Web.Service”。</title>
IService文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;namespace MySqlForNet.Web
{
// 注意: 如果更改此处的接口名称 "IService",也必须更新 Web.config 中对 "IService" 的引用。
[ServiceContract]
public interface IService
{
[OperationContract]
void DoWork();
}
}
Service文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;namespace MySqlForNet.Web
{
// 注意: 如果更改此处的类名 "Service",也必须更新 Web.config 中对 "Service" 的引用。
public class Service : IService
{
public void DoWork()
{
}
}
}
web文件
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MySqlForNet.Web.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MySqlForNet.Web.ServiceBehavior"
name="MySqlForNet.Web.Service">
<endpoint address="" binding="BasicHttpBinding" contract="MySqlForNet.Web.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
请高人指点一下。
答案
全部回复
-
首先要确保 http://localhost:1051/Service.svc 你这个wcf ie可以打开浏览
-
wcf ie不能被浏览。
“/”应用程序中的服务器错误。
无法找到 ServiceHost 指令中作为服务属性值提供的类型“MySqlForNet.Web.Service”。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: 无法找到 ServiceHost 指令中作为服务属性值提供的类型“MySqlForNet.Web.Service”。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[InvalidOperationException: 无法找到 ServiceHost 指令中作为服务属性值提供的类型“MySqlForNet.Web.Service”。] System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +4072062 System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +11656092 System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +42 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479 [ServiceActivationException: 由于编译过程中出现异常,无法激活服务“/Service.svc”。异常消息为: 无法找到 ServiceHost 指令中作为服务属性值提供的类型“MySqlForNet.Web.Service”。。] System.ServiceModel.AsyncResult.End(IAsyncResult result) +11527290 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176 System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +278 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
-
-
Check out this web site :
WCF, Service attribute value in the ServiceHost directive could not be found.
esp take a detail looking at the first replay ,cauz it has two links ,which offer great help.
I think u can get what u want .