我正在自托管 OData 应用程序。这目前涉及很多硬编码:在我的 DataService 类本身中:
public static void InitializeService(
DataServiceConfiguration config)
{
// Provide read-only access to all entries and feeds.
config.SetEntitySetAccessRule(
"*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
config.UseVerboseErrors = true;
config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V2;
}
初始化时:
Type servicetype = typeof(MessageDataService);
Uri baseaddress = new Uri("http://localhost:8000/messageData");
Uri[] baseaddresses = new Uri[] { baseaddress };
using ( DataServiceHost dshost = new DataServiceHost(servicetype, baseaddresses))
{
dshost.Open();
//blah
}
我认为这可以用“yuk”来充分概括。现在我可以通过App.config
. 数据服务也有什么开箱即用的东西,还是我应该推出自己的配置类?