【问题标题】:Meta data issue wcf rest元数据问题 wcf rest
【发布时间】:2012-03-15 21:25:38
【问题描述】:

所以试图创建一个休息服务,但我一直收到错误:

如果我尝试在浏览器中运行它,我会得到: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();
        }
    }
}

【问题讨论】:

    标签: c# asp.net wcf rest


    【解决方案1】:

    您正在使用 WebHttpBinding 定义 REST 样式 WCF 服务。

    WCF 测试客户端仅可用于 SOAP 服务 - 不适用于 REST 服务。可以使用常规浏览器或 Fiddler 等工具测试 REST 服务。

    您收到的错误消息几乎表明您在某个地方也有一个*.svc,这会妨碍您。是这样吗?

    【讨论】:

    • 是的,但是如果我右键单击并在浏览器中查看,我会得到类型 'WcfService2.Service1',作为 ServiceHost 指令中的服务属性值提供的找不到。
    • @Garrith:再说一遍——你不能这样做(在浏览器中查看)——那是针对 SOAP 服务的。您需要实际运行您的控制台应用程序,以便激活正确的服务主机和正确的地址....
    • 我没有控制台应用?
    • @Garrith:当然可以!那是class program { ... static void Main(......) ......或者它可能是一个 WInforms 应用程序 - 你肯定有一个 应用程序 在这里实例化正确的服务主机 - 该应用程序必须运行让您连接到 WCF 服务
    猜你喜欢
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    • 2011-12-15
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多