【发布时间】:2011-08-21 17:19:58
【问题描述】:
我正在使用 .NET 4 WCF 公开以下 REST-full webservice
[OperationContract]
[WebGet]
void Test();
由于这是一个面向开发人员的程序,我想支持 REST-full HTTP 开发人员以及喜欢使用 WSDL 的开发人员。我的方法是声明服务两次以公开传统的 WSDL 和 REST 端点:
Web.config
<serviceHostingEnvironment aspNetCompatibilityEnabled="True" multipleSiteBindingsEnabled="true" >
<serviceActivations >
<add relativeAddress ="~/KeyService.svc" service="SecretDistroMVC3.Services.KeyService3"/>
</serviceActivations>
</serviceHostingEnvironment>
全球.asax
void Application_Start(object sender, EventArgs e)
{
// The following enables the WCF REST endpoint
//ASP.NET routing integration feature requires ASP.NET compatibility. Please see
// 'http://msdn.microsoft.com/en-us/library/ms731336.aspx
RouteTable.Routes.Add(new ServiceRoute("KeyService3", new WebServiceHostFactory(), typeof(KeyService3)));
问题
由于我不喜欢在两个位置声明服务,我该如何在 config 中配置两个端点,或者在 Application_Start 中配置两个端点?
例子
【问题讨论】:
标签: wcf rest .net-4.0 routetable wcf-rest-starter-kit