【发布时间】:2010-09-22 20:10:36
【问题描述】:
我有一个从 Windows 服务 (.NET 3.5) 工作的 WCF REST 服务。为了更容易构建和调试,我想从控制台运行它。当我这样做时,我正在控制台应用程序中设置端点。当我创建一个端点时,它失败并出现以下错误: “在服务‘System.RuntimeType’实现的合同列表中找不到合同名称‘IRestService’。”
我的界面确实附有 [ServiceContract]:
namespace RestServiceLibrary
{
[ServiceContract]
public interface IRestService
...
这是控制台应用程序:
namespace RestServiceConsole
{
class Program
{
static void Main(string[] args)
{
WebServiceHost2 webHost = new WebServiceHost2(typeof(RestService), new Uri("http://localhost:8082"));
ServiceEndpoint ep = webHost.AddServiceEndpoint(typeof(IRestService), new WebHttpBinding(), "");
ServiceDebugBehavior stp = webHost.Description.Behaviors.Find<ServiceDebugBehavior>();
stp.HttpHelpPageEnabled = false;
webHost.Open();
Console.WriteLine("Service is up and running");
Console.WriteLine("Press enter to quit ");
Console.ReadLine();
webHost.Close();
}
}
}
为什么会出现此错误?我该如何解决?
【问题讨论】:
-
请原谅我问的很明显,但是您的控制台应用程序中是否有对服务库 (.dll) 的引用?
-
没什么太明显的。 :-) 我确实有参考。
-
而
RestService的定义是什么?