C# 如何摆脱;此服务的元数据发布当前已禁用";在WCF中

C# 如何摆脱;此服务的元数据发布当前已禁用";在WCF中,c#,wcf,C#,Wcf,如何摆脱WCF中的“此服务的元数据发布当前已禁用” 我的目标是以默认url显示主页。 我的代码 [ServiceContract] public interface IFileHost { [OperationContract, WebGet(UriTemplate = "/{filename=null}")] Stream Files(string filename); // TODO: Add your service operations here } publ

如何摆脱WCF中的“此服务的元数据发布当前已禁用”

我的目标是以默认url显示主页。 我的代码

[ServiceContract]
public interface IFileHost
{
    [OperationContract, WebGet(UriTemplate = "/{filename=null}")]
    Stream Files(string filename);

    // TODO: Add your service operations here
}

public class Service1 : IFileHost
{
    public System.IO.Stream Files(string filename)
    {
        string rattex;
        if (filename==""||string.IsNullOrEmpty(filename))
        {
            rattex = "home";
        }
        else
        {
            rattex = "<html><body>" + filename + "</body></html>";
        }
        StreamReader ret = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(rattex)));
        Stream stream = ret.BaseStream;
        WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";

        //Set the correct context type for the file requested.

        return stream;
    }
}

class Program
{
    static void Main(string[] args)
    {
        string baseAddress = "http://" + Environment.MachineName + ":8434/";
        ServiceHost host = new ServiceHost(typeof(Service1), new Uri(baseAddress));
        host.AddServiceEndpoint(typeof(IFileHost), new  WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior()  );

        host.Open();

        Console.WriteLine("Service is running");
        Console.Write("Press ENTER to close the host");
        Console.ReadLine();
        host.Close();
    }
}
[服务合同]
公共接口IFileHost
{
[OperationContract,WebGet(UriTemplate=“/{filename=null}”)]
流文件(字符串文件名);
//TODO:在此处添加服务操作
}
公共类服务1:IFileHost
{
public System.IO.Stream文件(字符串文件名)
{
绳鼠;
如果(文件名==“”| | string.IsNullOrEmpty(文件名))
{
rattex=“家”;
}
其他的
{
rattex=“”+文件名+”;
}
StreamReader ret=新的StreamReader(新的MemoryStream(Encoding.ASCII.GetBytes(rattex));
Stream=ret.BaseStream;
WebOperationContext.Current.OutgoingResponse.ContentType=“text/html”;
//为请求的文件设置正确的上下文类型。
回流;
}
}
班级计划
{
静态void Main(字符串[]参数)
{
string baseAddress=“http://“+Environment.MachineName+”:8434/”;
ServiceHost主机=新ServiceHost(类型为(Service1),新Uri(基地址));
host.AddServiceEndpoint(typeof(IFileHost),new-WebHttpBinding(),“”)。Behaviors.Add(new-WebHttpBehavior());
host.Open();
Console.WriteLine(“服务正在运行”);
控制台。写入(“按ENTER键关闭主机”);
Console.ReadLine();
host.Close();
}
}
我想摆脱这个页面,并获得一个空字符串的主页
您需要向服务中添加元数据端点。有关如何以编程方式执行此操作的更多信息,请参阅。

您是否实际阅读了错误页面,它会准确地告诉您错误所在,包括修复错误的步骤。我想没有人理解我的qs。我说我不要这一页。当没有/{filename}时,我希望服务返回主页。当访问原始url时,它仍然应该使用空输入调用服务。我不需要这些东西。我的目标是创建自己的Web服务器。