我正在尝试编写一个通用主机进程(WinForm),它托管同一合同的不同 WCF 服务实现。当我运行第一个时,它工作正常,但是当我使用不同的地址启动另一个(并行)时,我会两次使用相同的地址(地址和端口)-> 路径虽然不同..
private bool InitializeServiceHost()
{
bool isInitialized = true;
try
{
Log.InfoFormat("Loading service DLL {0} and class {1}", _dllPath, _serviceClassName);
var asm = Assembly.LoadFile(_dllPath);
_service = (IGfnService) asm.CreateInstance(_serviceClassName);
if (_service == null)
throw new ApplicationException(string.Format("Could not instansiate {0} from DLL {1}", _serviceClassName, _dllPath));
_service.Init(_myGuidStr);
Uri uri = new Uri("net.tcp://localhost:9085/GfnService/" + _myGuidStr);
var host = new ServiceHost(_service, uri);
Log.InfoFormat("About to open host, State: {0}, URI: {1} ", host.State, uri);
host.Open();
_serviceUri = uri.ToString();
Log.InfoFormat("Gfn service started successfully, State: {0}, URI: {1} ", host.State, uri);
}
catch (Exception ex)
{
Log.Error(ex.Message, ex);
isInitialized = false;
Application.Exit();
}
return isInitialized;
}
任何帮助将不胜感激....