繁体   English   中英

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

[英]How to get rid of “Metadata publishing for this service is currently disabled” in WCF

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

我的目标是在默认URL上显示主页。 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();
    }
}

我想摆脱此页面并获得一个空字符串的主页 在此处输入图片说明

您需要向服务添加元数据终结点。 有关如何以编程方式执行此操作的更多信息,请参见http://msdn.microsoft.com/zh-cn/library/aa738489(v=vs.110).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM