0

このガイドに従って、iis でサービスを動作させることができました。 https://code.google.com/p/autofac/wiki/WcfIntegration#Self-Hosted_Services

ただし、休憩サービスをホストする必要もあります。本当に休息だけで生きていける。

しかし、入手可能なドキュメントでは、まだ成功していません。

wcf(was)+autofac を使用して REST サービスで動作させるための適切なガイドはありますか?

私はエンドポイントを正しく取得していないようです。実際にはエンドポイントはまったくありません。

私のコード、どこで何かを見逃しましたか?

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 で残りのサービスを照会できます。

4

2 に答える 2

0

これを解決するには. config で autofac AutofacServiceHostFactory への参照を削除しました。次に、ビヘイビアを使用して手動でエンドポイントを作成しました。

サービスの .svc ファイルで AutofacServiceHostFactory を使用しました。

これは私がやりたい方法ではありませんでしたが、それ以外の場合は、残りのエンドポイントと basichttp soap エンドポイントの両方が機能しませんでした。

誰かがより良い解決策を持っている場合、私はあなたに答えます。


@John Meyer コードサンプルのリクエストに応じて、古いコードを見つけることができました。

私のフォルダー Services の EmailService.svc のようなサービスは、次のように編集します。

<%@ ServiceHost Language="C#" Debug="true" 
Service="Services.IEmailService, Services" 
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"
 %>

web.config で

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Autofac" publicKeyToken="x" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
  </dependentAssembly>
  <dependentAssembly>

AppStart クラス

public static class AppStart
{
    public static void AppInitialize()
    {
        IContainer container = AutofacContainerBuilder.BuildContainer();
        AutofacHostFactory.Container = container;}
}
...

コンテナを別のクラスに分離しました。Autofac を使用する正しい使用法を忘れないでください。

コンテナをセットアップするためのクラス内のメソッド

public static IContainer BuildContainer()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<EmailService>().As<IEmailService>();
            return builder.Build();
        }
于 2013-10-14T13:30:00.773 に答える