Tuesday, March 13, 2012 11:45 AM
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
ServiceHosthostSystem = newServiceHost(typeof(WKI.Cosmo.Business.ClientServices));
BindingtcpBinding = newNetTcpBinding(SecurityMode.None, true); hostSystem.AddServiceEndpoint(typeof(WKI.Cosmo.Interop.IClientServices), tcpBinding, "IClientServices2.svc");
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 ?
Tuesday, March 13, 2012 11:50 AM
Follow the answer in this thread where I talk about the ServiceHostFactory
- Proposed As Answer by Dragan Radovac Thursday, March 15, 2012 4:29 PM
Tuesday, March 13, 2012 1:55 PM
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 2:01 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:
Tuesday, March 13, 2012 10:49 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)
Thursday, March 15, 2012 6:22 AMModerator
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.