iis 8 - AppInitialize not firing in WCF Service Application on WIndows Server 2012 -
we have wcf service applications deployed windows server 2012.
in these services, there class called initializer in /app_code/ folder. class follows;
public class initializer { public static microserviceinitilization.msinit iinit = null; public static void log_string(string line) { //if (string.isnullorempty(app_path)) //{ // return; //} system.text.stringbuilder sb = new stringbuilder(); sb.append(line + environment.newline); string log_path = system.web.hosting.hostingenvironment.applicationphysicalpath; file.appendalltext(log_path + "log.txt", sb.tostring()); sb.clear(); } public static void appinitialize() { log_string("appinitialize called"); // called on startup microserviceinitilization.msinit iinit = new microserviceinitilization.msinit(configurationmanager.appsettings["log_directory"], configurationmanager.appsettings["service_endpoint_name"]); } }
when application run in local dev environment ( iis7 on windows7 ), initialization code executed expected , log file generated. when deployed wcf service windows 2008r2 server iis7.5, initialization code fired expected.
when same application deployed our windows 2012 production environment, the services work expected, none of initialization code fired; there no log files & other init code in msinit shows no record of having executed.
we tried working "application initialization" features of iis8 on server, nothing obvious seemed work.
in attempt try other things, changed initialization code use servicehostfactory pattern so;
public class cbhmicroservice : servicehostfactory { public static void log_string(string line) { //if (string.isnullorempty(app_path)) //{ // return; //} system.text.stringbuilder sb = new stringbuilder(); sb.append(line + environment.newline); string log_path = system.web.hosting.hostingenvironment.applicationphysicalpath; file.appendalltext(log_path + "log.txt", sb.tostring()); sb.clear(); } public override servicehostbase createservicehost(string constructorstring, uri[] baseaddresses) { log_string("createservicehost called"); log_string(configurationmanager.appsettings["log_directory"]); log_string(configurationmanager.appsettings["service_endpoint_name"]); microserviceinitilization.msinit iinit = new microserviceinitilization.msinit(configurationmanager.appsettings["log_directory"], configurationmanager.appsettings["service_endpoint_name"]); iinit.log_string("createservicehost called"); // return new servicehost(typeof(initializer), baseaddresses); return new servicehost(typeof(cbh.idproofing.kbausersservice.kbausers), baseaddresses); } }
and .svc file looks this;
<%@ servicehost language="c#" debug="true" service="cbh.idproofing.kbausersservice.kbausers" codebehind="kbausers.svc.cs" factory="cbh.idproofing.kbausersservice.app_code.cbhmicroservice" %>
again: locally, code firing expected , desired log files being created , entries in log file correct.
the log_string function shown in above code drop log file in same path .svc file. same log_string function exists in microserviceinitilization dll, logs defined folder.
at point, @ loss why these services work on other versions of windows except 2012.
Comments
Post a Comment