in

DotNetMarche

.NET Framework User Group delle Marche

This Blog

Syndication

ExternalBlogs

April 2009 - Posts

  • Silverlight/WPF UIElement: how to find and ancestor of type <T> procedurally

    Suppose you have the following scenario you have two templated UserControl: UCContainer - is a graphical container for other controls, it can be used to contain different kinds of controls, it can be skinned using a template that will be changed by the...
  • Optimizing regular expression part 2

    If you look at this post, you can see that I had some performance problem with regular expression. After the first round of optimization it turns out that performances are still quite slow. My next step will be to remove regular expression doing search by a custom algorithm. I need to search word in text [...]
  • NHibernate ICriteria and composite-id with key-many-to-one

    Suppose you have a legacy database, and an entity called ViewOfBaseData that have this id. <composite-id class="ViewOfBaseDataId" name="Id" > <key-many-to-one class="LinkResult" name="Link" column="AnalysisId" lazy="proxy" /> <key-property name="AnalysisDate" type="System.DateTime" column="AnalysisDate" /> </composite-id> Now suppose you need to retrieve all object ViewOfBaseData linked to a LinkResult object with a property KeyList [...]
  • Microsoft Office SharePoint Server SP2

    Post *di servizio* per segnalarvi l’uscita della SP2 per MOSS/WSS. L’aggiornamento di SharePoint alla SP2 è molto importante per chi volesse trovarsi in vantaggio per l’upgrade alla prossima versione di MOSS (2010). Qui trovate la lista completa di fixed e features apportate. Visto che è tempo di aggiornamenti vi consiglio di non perdere anche la SP2 [...]
  • Java versus .Net programmers

    I’ve come across this post, that deals about java and .net programmers. I must admit that the situation is the one depicted by the author, probably in the average, java programmers are better accustomed with stuff like DI, IoC, ORM, AOP, and design principle, respect of .net developer; but is it really ok to reduce [...]
  • Hosting wcf service in precompiled web sites

    The situation is the following: I have a web site (not a web application) that have one wcf service hosted with the classic svc file. Everything works as expected, until I use a Deployment Web Project to build a site with “allow the precompiled site to be updatable” to false. Now if I browse the [...]
  • LINQ to CSV

    Veramente utile!!! :D http://www.codeproject.com/KB/linq/LINQtoCSV.aspx Technorati Tag: LINQ , CSV Read More...
  • Idi di Marzo

    Ottimo questo librlo di Manfredi, l’ho terminato nel week-end e devo dire che, pur essendo un testo storico, non tralascia un ottimo filo romanzesco che narra della vita più che della fine di Caio Giulio Cesare e della Roma che oggi noi tutti conosciamo. Bellissima la figura della legione Romana e di Publio Sestio (detto [...]
  • Integrare Castle Windsor con Wcf a costo zero.

    Castle Windsor è senza dubbio uno dei motori di inversione di controllo più gettonati. L’aspetto interessante è che al suo interno si trovano molte estensioni, chiamate generalmente Facility, per gestire gli scenari più comuni. Stamane mi è capitato di usare l’integrazione con WCF. In pratica si tratta di una estensione che ci permette di risolvere i servizi con un WindsorContainer.

    Questa funzionalità è decisamente interessante, dato che in questo modo si risolvono tutti i problemi di dipendenza tra i vari servizi e tra i servizi e componenti esterni. Grazie ad un motore di inversione di controllo come Windsor si possono configurare i servizi in maniera estremamente flessibile. Ad esempio consideriamo il seguente servizio

    [ServiceContract]
    public interface IKernel
    {
     [OperationContract(Name = "Test")]
     Int32 Test();

    Implementato dalla seguente classe

    public class Kernel : IKernel 
    {
       public Int32 TestValue { get; set; }
    
       #region IKernel Members
    
       public Int32 Test()
       {
          return TestValue;
       }

    Come si può vedere la classe dipende dal parametro TestValue, in questo caso basta configurare il tutto con castle.

    <configuration xmlns="http://www.tigraine.at/windsor-configuration.xsd">
       <components>
          <component id="Kernel" service="Test.Services.Interfaces.IKernel, Test.Services.Interfaces"
                     type="Test.Services.Impl.Kernel, Test.Services.Impl" >
             <parameters>
                <TestValue>42</TestValue>
             </parameters>
          </component>
       </components>
    
       <facilities>
          <facility
              id="CastleWcfItegration"
              type="Castle.Facilities.WcfIntegration.WcfFacility, Castle.Facilities.WcfIntegration">
          </facility>
       </facilities>
       
    </configuration>

    La particolarità è che si è specificata la facility di CastleWcfIntegration, in questo modo si può hostare un servizio con il custom Host definito nella facility

    using (DefaultServiceHost host = (DefaultServiceHost)new DefaultServiceHostFactory().CreateServiceHost(
       typeof(IKernel).AssemblyQualifiedName, new Uri[0]))
    {
        Uri serviceAddress = new Uri("http://localhost:7601/Kernel");
        Uri serviceMexAddress = new Uri("http://localhost:7601/Kernel/mex");
        host.Description.Behaviors.Add(new ServiceMetadataBehavior());
        host.AddServiceEndpoint(typeof(Test.Services.Interfaces.IKernel), new BasicHttpBinding(), serviceAddress);
        host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), serviceMexAddress);
       
       host.Open();
       Console.WriteLine("Host started");
       System.Console.ReadKey();
    }

    L’unica differenza con gli esempi standard di WCF è che in questo caso l’host è di tipo DefaultServiceHost, definito in Castle.Facilities.WcfIntegration. Se lanciate il programma e provate ad invocare il servizio con il WcfTestClient potrete notare che il valore di ritorno del metodo Test è 42, ovvero il nostro servizio è stato risolto in maniera completamente automatica da Castle.

    Alk.

    Tags:

  • Castle Wcf facility integration on windows service or console.

    Castle has a great facility to resolve Wcf services with castle windsor. This is really useful because it helps you when your concrete service classes have dependency to be resolved. There are a lot of tutorials or blog posts on how to configure it when you want to host service in IIS, but little bit [...]
  • The importance of overriding ToString for tests

    Standard behavior of ToString is to print class or structure name. Sometimes if you never need to call tostring for class in application you will avoid to override this basic behavior. Suppose you have this simple structure. public struct Range { public Int32 Left; public Int32 Rigth; This is a simple structure [...]
  • Optimizing Regular expression

    I have an application where I do a lot of search for pattern in text and I use a lot of regular expression. The program runs well, until the amount of text it has to search into is grown tremendously. It reaches a point where the standard daily task that was completed in a couple [...]
  • Will OpenOffice survive the Oracle-Sun takeover?

    Raffaele qualche giorno fa, aveva accennato già qualche *sacrosanto* dubbio nel suo blog, intanto ieri è uscito un interessante post di Christopher Dawson, guarda caso sulla sezione education di zdnet. Christopher d’altro canto si *limita* a sollevare la questione economica nel comparare OpenOffice ad altre suite per l’Office Automation a pagamento. Io non sono di questo [...]
  • Decouple controllers and other objects from context in asp.net mvc

    When I decided to write down a little class to manage a menu, I created a simple object that reads the menu data in xml, and transform it into a series of MenuItem object. The first thing I wanted to do is writing some test to verify that the logic is ok, but since my [...]
  • Novità importanti per OOXML – IS29500

    Andrea parla dell’accetazione di IS 29500 da parte di INCITS, intanto anche nel WG4 si stanno dibattendo importanti discussioni circa le specifiche del nuovo OOXML, eccovene alcune pubbliche: Losing data the silent way - ISO8601-dates Versioning of OOXML (thank you for all the fish) The Namespace Problem
More Posts Next page »
Powered by Community Server (Commercial Edition), by Telligent Systems