Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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
完全公开WCF服务REST_Wcf - Fatal编程技术网

完全公开WCF服务REST

完全公开WCF服务REST,wcf,Wcf,我创建了一个全新的WCF服务。我创建这项服务只是说添加新项目…->VisualStudio中的WCF服务。然后,我稍微编辑了一下合同,如下所示: [ServiceContract] public interface IMyService { [OperationContract] [WebGet(UriTemplate = "/Authenticate/{username}/{password}", ResponseFormat = WebMessageFormat.Json)]

我创建了一个全新的WCF服务。我创建这项服务只是说添加新项目…->VisualStudio中的WCF服务。然后,我稍微编辑了一下合同,如下所示:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    [WebGet(UriTemplate = "/Authenticate/{username}/{password}", ResponseFormat = WebMessageFormat.Json)]
    bool Authenticate(string username, string password);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(IncludeExceptionDetailInFaults = false)]
public class MyService : IMyService
{
    public bool Authenticate(string username, string password)
    {
        try
        {
            return false;
        }
        catch (Exception ex)
        {
            throw new ApplicationException("Unknown exception");
        }
    }
}
我的操作如下所示:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    [WebGet(UriTemplate = "/Authenticate/{username}/{password}", ResponseFormat = WebMessageFormat.Json)]
    bool Authenticate(string username, string password);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(IncludeExceptionDetailInFaults = false)]
public class MyService : IMyService
{
    public bool Authenticate(string username, string password)
    {
        try
        {
            return false;
        }
        catch (Exception ex)
        {
            throw new ApplicationException("Unknown exception");
        }
    }
}
当我访问时:在我的浏览器窗口中,会出现一个空屏幕。我希望JSON语法中出现false。我做错了什么


谢谢大家!

使用Fiddler之类的工具查看实际的HTTP消息。有助于调试

第二,你的请求URL是错误的。试试这个:

你有一个SVC文件,对吗?如果你在IIS中托管这个,你需要它。如果您在WebServiceHost对象中自托管它,那么您不需要它们

    using( WebServiceHost host = new WebServiceHost( typeof( MyService) ) )
    {
        host.Open();
        Console.WriteLine( "Service is running" );
        Console.WriteLine( "Press enter to quit..." );
        Console.ReadLine();
        host.Close();
    }

你说得对。我有一个SVC文件。后来我编辑了这篇文章。但我还是有一个空白屏幕。空白屏幕?你用Firefox来测试这个?您可能会遇到400或404错误。IE是的,IE会告诉你HTTP错误。也可以试试小提琴手。非常好的工具。你是如何主持这项服务的?在IIS中?VisualStudio开发服务器?使用WebServiceHost自托管?如果我发现创建一个控制台应用程序并使用它自托管web应用程序会使调试更容易。在我安装fiddler之后,我发现我遇到了一个400错误。但我不明白我做错了什么。谢谢。你是如何主持这项服务的?请发布您的配置文件。另一件在过去引起我注意的事情是项目文件中的一个问题。打开项目文件并确保此元素为空: