【发布时间】:2012-04-09 10:42:51
【问题描述】:
我有一个名为 WcfService2 的服务(我知道原来的),它有一个带有公共接口的 IService.cs 文件:
namespace WcfService2
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "/{value}")]
string GetData(string value);
}
}
然后我有我的公共类 Service1.svc.cs 文件,它返回一个字符串,如下所示:
namespace WcfService2
{
public class Service1 : IService1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
}
}
我现在正在尝试使用这样的控制台应用来托管此服务:
namespace Host
{
class Program
{
static void Main(string[] args)
{
WebHttpBinding binding = new WebHttpBinding();
WebServiceHost host =
new WebServiceHost(typeof(IService1));
host.AddServiceEndpoint(typeof(IService1),
binding,
"http://localhost:8000/Hello");
host.Open();
Console.WriteLine("I DONT LIKE REST!");
Console.WriteLine("Press <RETURN> to KILL REST FOR GOOD");
Console.ReadLine();
}
}
}
但是我运行后报错:
ServiceHost 仅支持类服务类型。
所以这显然与我的 IService 是公共接口类型有关。但是我不知道如何创建它,当我第一次创建WCF Service application 时,它会为您提供两个标准文件 IService 和 Service.svc 文件,如果我删除其中一个或,并且仅在我尝试添加时在一个类中实现此解决方案本地灵魂中的网络服务没有找到。
有没有办法修改主机代码?
【问题讨论】:
-
还有一个答案可以试试@stackoverflow.com/q/19306395/16391
标签: c# .net wcf exception-handling wcf-rest