2
在元數據頁下面給出了一個實例代碼永遠不會在ServiceStack元數據描述丟失
[Description("GET account, all or by list of groups or by list of logins")]
指定的描述是有需要才能被設定描述元數據頁面展現了一個特殊的配置?
代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using ServiceStack.ServiceHost;
using System.Runtime.Serialization;
using ServiceStack.WebHost.Endpoints;
namespace ConsoleApplication2
{
public class User
{
public User()
{
}
public int login;
public string group;
public string name;
}
[Description("GET account, all or by list of groups or by list of logins")]
[Route("/accounts")]
public class Accounts : IReturn<List<User>>
{
public string[] groups { set; get; }
public int[] logins { set; get; }
public Accounts() { }
public Accounts(params int[] logins)
{
this.logins = logins;
}
public Accounts(params string[] groups)
{
this.groups = groups;
}
}
public class Host : AppHostHttpListenerBase
{
public Host() : base("Test",
typeof(Accounts).Assembly)
{
}
public override void Configure(Funq.Container container)
{
SetConfig(new EndpointHostConfig {
EnableFeatures = Feature.All
});
}
}
public class Servce : IService
{
public object Get(Accounts request)
{
return new List<User>(){new User()};
}
}
class Program
{
static void Main(string[] args)
{
var host = new Host();
host.Init();
host.Start("http://+:12345/");
Console.ReadLine();
}
}
}
導航到http://localhost:12345/json/metadata?op=Accounts
產生
<body>
<a id="logo" href="http://www.servicestack.net" title="servicestack"></a>
<h1>Test</h1>
<form>
<div>
<p><a href="/metadata"><back to all web services</a></p>
<h2>Accounts</h2>
<div class="example">
<!-- REST Examples -->
...
再次感謝 快速的後續問題:什麼是ApiMember註解嗎?因爲當我使用它時,我在元數據中看不到任何區別。只有Api屬性似乎添加到html中,與Api上的摘要和註釋相同 – Dmitry 2013-02-12 06:00:43
它在Swagger中使用,但不在'/ metadata'頁面中 - 將很快應用。 – mythz 2013-02-12 06:03:21
@mythz出於興趣,如果你想將它作爲更復雜的類型發佈,那麼parametertype =「body」和datatype =「MyrequestDTO」? – Junto 2013-02-22 17:03:02