按照本指南,我设法让服务在 iis 上运行。 https://code.google.com/p/autofac/wiki/WcfIntegration#Self-Hosted_Services
但是,我还需要它托管一个休息服务。我实际上只能靠休息来生活。
但是有了可用的文档,我还没有成功。
有没有人有一个很好的指南来让它与 wcf(was)+autofac 一起使用休息服务?
我似乎没有得到正确的端点,实际上根本没有端点。
我的代码,我在哪里错过了什么?
namespace WcfServiceHost.Infrastructure
{
public class AutofacContainerBuilder
{
public static IContainer BuildContainer()
{
var builder = new ContainerBuilder();
builder.RegisterType<LoginFactory>().As<ILoginFactory>();
builder.RegisterType<SupplierHandler>().As<ISupplierHandler>();
builder.RegisterType<UserHandler>().As<IUserHandler>();
builder.RegisterType<SupplierRepository>().As<ISupplierRepository>();
builder.RegisterType<TidsamProductSupplierProxy>().As<ILogin>();
builder.RegisterType<StoreService>().As<IStoreService>();
//builder.RegisterType<StoreService>();
return builder.Build();
}
}
}
<%@ ServiceHost Language="C#" Debug="true"
Service="Services.IStoreService, Services"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"
%>
namespace WcfServiceHost.App_Code
// ReSharper restore CheckNamespace
{
public static class AppStart
{
public static void AppInitialize()
{
// Put your container initialization here.
// build and set container in application start
IContainer container = AutofacContainerBuilder.BuildContainer();
AutofacHostFactory.Container = container;
// AutofacWebServiceHostFactory AutofacServiceHostFactory
RouteTable.Routes.Add(new ServiceRoute("StoreService", new RestServiceHostFactory<IStoreService>(), typeof(StoreService)));
}
}
}
public class RestServiceHostFactory<TServiceContract> : AutofacWebServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
ServiceHost host = base.CreateServiceHost(serviceType, baseAddresses);
var webBehavior = new WebHttpBehavior
{
AutomaticFormatSelectionEnabled = true,
HelpEnabled = true,
FaultExceptionEnabled = true
};
var endpoint = host.AddServiceEndpoint(typeof(TServiceContract), new WebHttpBinding(), "Rest");
endpoint.Behaviors.Add(new WebHttpBehavior { HelpEnabled = true });
endpoint.Name = "rest";
endpoint.Behaviors.Add(webBehavior);
return host;
}
}
配置:
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add factory="Autofac.Integration.Wcf.AutofacServiceHostFactory"
relativeAddress="~/StoreService.svc"
service="Services.StoreService" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" />
</handlers>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
然后我确实得到了一个端点。但是,一旦我更改为 AutofacWebServiceHostFactory,我就没有端点,也没有休息/帮助。但是,我可以在 IStoreService 中查询其余服务。