![](/img/trans.png)
[英]WCF Service Library (IIS): Metadata publishing for this service is currently disabled
[英]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.