我正在尝试托管可以从 Azure 服务总线中继的 REST 服务。我看到了这个博客,看起来它可以回答我的问题,但不幸的是,我得到了相同的结果。
这是我尝试在浏览器中访问服务时收到的异常。
该服务无法激活,因为它不支持 ASP.NET 兼容性。为此应用程序启用了 ASP.NET 兼容性。在 web.config 中关闭 ASP.NET 兼容模式,或将 AspNetCompatibilityRequirements 属性添加到服务类型,并将 RequirementsMode 设置为“允许”或“必需”。
ServiceHostFactory
如果我从连接到 Azure 服务总线 ( viabasicHttpRelayBinding
) 的服务中排除 Azure 端点注册,我不会收到此错误,我可以在本地访问该服务。它与托管 RESTful 服务 ( webHttpBinding
) 和 Azure 服务总线中继绑定 ( basicHttpRelayBinding
) 有关。
在 global.asax 我添加服务托管
protected void Application_Start(object sender, EventArgs e)
{
// Add REST service hosting.
RouteTable.Routes.Add(new ServiceRoute("myservice/rest",
new CustomWebServiceHostFactory(typeof(IMyService)),
typeof(MyServiceProvider)));
}
我已按如下方式装饰了我的服务提供者:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyServiceProvider : IMyService
{
...
}
我在 IIS 中运行的服务接口的 web.config 具有以下值:
<configSections>
<sectionGroup name="system.serviceModel" type="System.ServiceModel.Configuration.ServiceModelSectionGroup, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="standardEndpoints" type="System.ServiceModel.Configuration.StandardEndpointsSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</sectionGroup>
</configSections>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="true">
<security mode="None"/>
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
...
</system.serviceModel>
有任何想法吗?