所以尝试创建一个休息服务,但我一直收到错误:
如果我尝试在浏览器中运行它,我会得到:The type 'WcfService2.Service1', provided as the Service attribute value in the ServiceHost directive could not be found.
namespace WcfService2
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public class HelloWorldService
{
[OperationContract]
[WebGet(UriTemplate = "")]
public string HelloWorld()
{
return "Hello world!";
}
}
}
namespace WcfService2
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
class Program
{
static void Main(string[] args)
{
WebHttpBinding binding = new WebHttpBinding();
WebServiceHost host =
new WebServiceHost(typeof(HelloWorldService));
host.AddServiceEndpoint(typeof(HelloWorldService),
binding,
"http://localhost:8000/Hello");
host.Open();
Console.WriteLine("Hello world service");
Console.WriteLine("Press <RETURN> to end service");
Console.ReadLine();
}
}
}
答案 0 :(得分:1)
您正在使用WebHttpBinding
定义 REST风格的 WCF服务。
WCF测试客户端仅适用于 SOAP 服务 - 不适用于REST服务。可以使用常规浏览器或Fiddler等工具测试REST服务。
您收到的错误消息几乎表明您在某处也有*.svc
,这会妨碍您。是这样的吗?