我有其中有一个IService.cs文件与一个公共接口命名WcfService2(原来我知道)服务:
I have a service named WcfService2 (original i know) which has an IService.cs file with a public interface:
namespace WcfService2
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "/{value}")]
string GetData(string value);
}
}
然后我有我的,它返回一个字符串,像这样的价值公共类Service1.svc.cs文件:
I then have my public class Service1.svc.cs file which returns a string for the value like so:
namespace WcfService2
{
public class Service1 : IService1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
}
}
我现在想用,像这样一个控制台应用程序主持此服务的:
I am now trying to host this service with a console app like so:
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();
}
}
}
不过,我得到一个错误我运行后:
But I get an error after I run it:
ServiceHost的只支持类服务类型。
ServiceHost only supports class service types.
所以,这显然涉及到我的IService是公共接口类型。但我不知道怎么回事,来创建它,当我第一次创建 WCF服务的应用程序
它给你的两个标准文件IService和Service.svc文件,如果我删除一个或,只有当我尝试添加本地soultion没有Web服务发现实现这个解决方案在一个类中。
So this obviously relates to my IService being of public interface type. But I dont know how else to create it, when I first created the WCF Service application
it gives you the two standard files IService and Service.svc files if I delete either or, and only Implement this solution in one class when I try to add the web service in local soultion nothing is found.
有没有办法来摆弄主机code?
Is there a way to fiddle with the host code?
我建议你改变这一点:
WebServiceHost host = new WebServiceHost(typeof(IService1));
这样:
WebServiceHost host = new WebServiceHost(typeof(Service1));