У меня есть приложение, в котором есть два файла .SVC для двух разных модулей.В существующем приложении мы выполняем вызовы один за другим в пределах одного потока.У меня никогда не было проблем.
В рамках рефакторинга я очистил их, назвав их этими службами из двух разных потоков (первый поток вызывает первый метод, а второй поток вызывает второй метод).Эти два метода даже разные.Иногда код выполняется без проблем.но иногда я получаю ошибку ниже, говоря, что не смог найти экземпляр.Опять же, эта ошибка не всегда возникает.
Exception:
RMS Conversion failed : System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: ComponentActivator:
could not instantiate Axis.Edc.Service.RMS.RMSConversionService (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
Castle.MicroKernel.ComponentActivator.ComponentActivatorException: ComponentActivator: could not instantiate RMS.RMSConversionService ----> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ----> System.InvalidOperationException: The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently. Note that instance members of DbContext and related classes are not guaranteed to be thread safe.
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator...).
Вот код вызова службы:
public EnumConversionStatus GenerateRmsImportFiles(int submissionId)
{
lock (new object())
{
using (var client = new RMSConversionService.RMSConversionServiceClient())
{
var result = client.GenerateRmsImportFiles(submissionId);
client.Close();
return result;
}
}
}
public EnumConversionStatus GenerateAirImportFiles(int submissionId)
{
lock (new object())
{
using (var client = new AIRConversionService.AirConversionServiceClient())
{
var result = client.GenerateAirImportFiles(submissionId);
return result;
}
}
}
Здесь у нас есть две разные конечные точки для 2 разных сервисов SVC.Также здесь у нас есть замок.Я не уверен, как именно обойти эту ошибку?
Спасибо, Рита