none
IIS/WAS hosting : wiring up everything in AppInitialize .. is it possible ?

    Question

  • hi, i'm trying to setup net.tcp on WAS with 0 config, that is, i want to setup everything programmatically (as in a windows service).

    I've tried to put this code in the AppInitialize method 

    ServiceHost
    hostSystem = newServiceHost(typeof(WKI.Cosmo.Business.ClientServices));    
    BindingtcpBinding = newNetTcpBinding(SecurityMode.None, true);          hostSystem.AddServiceEndpoint(typeof(WKI.Cosmo.Interop.IClientServices), tcpBinding,           "IClientServices2.svc");
    hostSystem.Open();

    this code is called but gives the following error.
    System.InvalidOperationException: Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [].

    This makes somehow sense, however of course i do not wabnt to register a base address since i'm hosted in IIS/WAS. Seems like this method is called to early.
    Is what i'm trying to do a supported way ? Is there any solution ?

    thank you

    enrico sabbadin

    Tuesday, March 13, 2012 11:45 AM

All replies

  • Follow the answer in this thread where I talk about the ServiceHostFactory

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/756cd975-4607-4fcb-9cd5-ad5cfd21ce1d

    • Proposed as answer by Dragan Radovac Thursday, March 15, 2012 4:29 PM
    Tuesday, March 13, 2012 11:50 AM
  • using ServiceHostFactory u can control the service instance to setup (i use it for a singelton as well), and other nice stuff.

    But how can i have no info in the web.config at all, still have IIS/WCF landing on my factory ?

    I think i need to hook something before in the call chain to do that. Appinitialize seems a nice place, however , from the error i get i don't kow how to grab the baseaddress (net.tcp://myserver/myvdir)., and i don't want to hardocode it.

    I hope i explained myself clearly now :)

    Tuesday, March 13, 2012 1:55 PM
  • You can use appsettings to store your baseaddress as a string in your web.config and read it in on Appinitialize. The article below shows how to do this:

    http://stackoverflow.com/questions/719928/how-do-you-modify-the-web-config-appsettings-at-runtime

    Tuesday, March 13, 2012 2:01 PM
  • ok .. i checked out better the documentation . with ServiceHostFactory  i can control service instance AND it's endpoint construction .. so  i can get rid of that stuff from the config ..

    But is there a way to get rid of svc files or the serviceactivations elments in the config fle .. and write this stuff in code as well ? appinitialize seems a good place but i don't know how to pick up the baseaddresses from IIS/WAS. (writing them in my custom section of the config file is not a good idea)

    Tuesday, March 13, 2012 10:49 PM
  • HI,

    As Sabbadin metioned, you could use the ServiceHostFactory class to use a custom ServiceHost in the IIS or WAS hosting environment, it provides CreateServiceHost method one of which parameter is baseAddress, as for this, please check this article.

    http://msdn.microsoft.com/en-us/library/aa395224.aspx

    Regards,
    Peter


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    • Marked as answer by Yi-Lun Luo Friday, April 06, 2012 2:23 AM
    • Unmarked as answer by Yi-Lun Luo Friday, April 06, 2012 2:24 AM
    Thursday, March 15, 2012 6:22 AM
    Moderator