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

时间:2014-05-30 22:42:03

标签: c# wcf

如何摆脱"此服务的元数据发布目前已停用"在WCF

我的目标是在默认网址上显示主页。 PFB我的代码

[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();
    }
}

我想摆脱这个页面并获得null字符串的主页 enter image description here

1 个答案:

答案 0 :(得分:1)

您需要向服务添加元数据端点。有关如何以编程方式执行此操作的详细信息,请参阅http://msdn.microsoft.com/en-us/library/aa738489(v=vs.110).aspx