Wednesday, May 5, 2010

WCF Alternative Config with MEF

This website describes how to use an alternate config file with WCF.

http://weblogs.asp.net/cibrax/archive/2009/09/08/client-configuration-in-wcf-4-0.aspx

Basically, this is a way to do it, also.

ConfigurationChannelFactory factory = null;
try
{
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string configFile = path + @"\FOT.Services.Plugins.RAT.MainServer.dll.config";

ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = configFile;

Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

System.ServiceModel.EndpointAddress endPointAddress = new System.ServiceModel.EndpointAddress("net.tcp://" + rigIP + ":8052/SatelliteAuthorizationService");

factory = new ConfigurationChannelFactory("NetTcpBinding_IAuthorizationService", config, endPointAddress);

EventLogger.LogEvent(EventLogger.LogCode.Debug, EventLogger.LogLevel.Trace, id: "877", className: "Moderator", methodName: "CreateWell", eventMessage: "Loaded Config File.");
}
catch (Exception ex)
{
EventLogger.LogEvent(EventLogger.LogCode.Unknown_Error, EventLogger.LogLevel.Error, id: "881", className: "Moderator", methodName: "CreateWell", eventMessage: ex.Message, stackTrace: ex.StackTrace);
}
IAuthorizationService client = factory.CreateChannel();
int error = client.CreateWell(authorizationKey, Convert.ToInt32(wellId), databaseName, productType, productVersion);

No comments:

Post a Comment