Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 元数据问题wcf rest_C#_Asp.net_Wcf_Rest - Fatal编程技术网

C# 元数据问题wcf rest

C# 元数据问题wcf rest,c#,asp.net,wcf,rest,C#,Asp.net,Wcf,Rest,因此,尝试创建rest服务时,我不断收到一个错误: 如果我尝试在浏览器中运行它,我会得到:找不到ServiceHost指令中作为服务属性值提供的类型“WcfService2.Service1”。 namespace WcfService2 { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and

因此,尝试创建rest服务时,我不断收到一个错误:

如果我尝试在浏览器中运行它,我会得到:
找不到ServiceHost指令中作为服务属性值提供的类型“WcfService2.Service1”。

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();
        }
    }
}
名称空间WcfService2
{
//注意:您可以使用“重构”菜单上的“重命名”命令同时更改代码和配置文件中的接口名称“IService1”。
[服务合同]
公共类HelloWorldService
{
[经营合同]
[WebGet(UriTemplate=”“)]
公共字符串HelloWorld()
{
返回“你好,世界!”;
}
}
}
命名空间WcfService2
{
//注意:您可以使用“重构”菜单上的“重命名”命令来同时更改代码、svc和配置文件中的类名“Service1”。
班级计划
{
静态void Main(字符串[]参数)
{
WebHttpBinding=新的WebHttpBinding();
WebServiceHost主机=
新的WebServiceHost(typeof(HelloWorldService));
host.AddServiceEndpoint(typeof(HelloWorldService),
结合
"http://localhost:8000/Hello");
host.Open();
Console.WriteLine(“你好世界服务”);
Console.WriteLine(“按到结束服务”);
Console.ReadLine();
}
}
}

您正在使用
WebHttpBinding
定义一个REST样式的WCF服务

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


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

是的,但如果我右键单击并在浏览器中查看,则无法找到ServiceHost指令中作为服务属性值提供的类型“WcfService2.Service1”。@Garrith:再次-您不能这样做(在浏览器中查看)-这是用于SOAP服务的。你需要实际运行你的控制台应用程序,以便激活正确的服务主机和正确的地址……我没有控制台应用程序用于此目的?@Garrith:当然有!这是
类程序{…static void Main(…)
…或者它可能是一个WInforms应用程序-您这里肯定有一个应用程序实例化了正确的服务主机-该应用程序必须运行,您才能连接到WCF服务