2010-07-30 5 views
1

Je suis en train d'organiser un service WCF dans une application console en utilisant Castle-Windsor 2.5 (.NET 4) avec le code suivant:Hôte de service WCF avec le château-Windsor IIS à l'extérieur avec le code que

 new WindsorContainer() 
      .AddFacility<WcfFacility>() 
      .Register(
      Component.For<IMyService>().ImplementedBy<MyService>() 
          .ActAs(new DefaultServiceModel() 
              .AddEndpoints(
              WcfEndpoint.BoundTo(new BasicHttpBinding()).At("http://localhost:1010/MyService"), 
              WcfEndpoint.BoundTo(MetadataExchangeBindings.CreateMexHttpBinding()).At("http://localhost:1010/MyService/mex")) 
             )); 

Je n'ai pas et je préfère ne pas avoir de config dans mon app.config pour WCF si possible.

Cela ne semble toutefois pas fonctionner (ne se plaint pas mais WcfTestUtil ne peut pas voir le service).

Est-ce que je manque quelque chose?

Répondre

1

Basé sur le lien de Khash de Google Groupes, voici le code strict minimum pour faire ce travail:

public void Install(IWindsorContainer container, IConfigurationStore store) 
{ 
    container 
     .AddFacility<WcfFacility>() 
     .Register(
      Component.For<ICoreService>() 
      .ImplementedBy<CoreService>() 
      .AsWcfService(new DefaultServiceModel() 
       .AddBaseAddresses("http://localhost:1000/core") 
       .AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding())) 
        .PublishMetadata(o => o.EnableHttpGet())) 
    ); 
} 
1

J'utilise wcfFacility 3.3.0 et hébergement dll service WCF dans les fenêtres de service c'est l'enregistrement des composants de travail pour moi : (ajouter Hosted())

public void Install(IWindsorContainer container, IConfigurationStore store) 
    { 
     container.AddFacility<LoggingFacility>(f => f.UseLog4Net()); 

     container 
      .AddFacility<WcfFacility>(f => 
      { 
       f.CloseTimeout = TimeSpan.Zero; 
      }); 


     string baseAddress = "http://localhost:8744/TVIRecorderWcfService/"; 

     container.Register(

      Component 
       .For<ITVIRecorderWcfService>() 
       .ImplementedBy<TVIRecorderWcfService>() 
       .AsWcfService(
       new DefaultServiceModel() 
        .AddBaseAddresses(baseAddress) 
        .Hosted() 
        //publish metadata doesn't work, have to do differently 
        //.PublishMetadata(x => x.EnableHttpGet()).Discoverable() 
        .AddEndpoints(WcfEndpoint 
         .BoundTo(new BasicHttpBinding())) 
         //.PublishMetadata(x=>x.EnableHttpGet()).Discoverable() 
         ).LifestyleSingleton() 
         , 

      Component 
       .For<ServiceBase>() 
       .ImplementedBy<TVIRecorderService>()); 
    } 

A voir par WcfTestClient util, le service doit publier est serviceMetadata Je dois ajouter manuellement serviceBehaviour et MetadataExchangeBindings après instanciation mon ServiceHost

var binding = MetadataExchangeBindings.CreateMexHttpBinding(); 
var mexAddress = "http://localhost:8744/TVIRecorderWcfService/mex"; 
var behaviour = new ServiceMetadataBehavior() {HttpGetEnabled = true}; 


serviceHost.Description.Behaviors.Add(behaviour); 
serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), binding, mexAddress); 
Questions connexes