Привет У меня есть 2013 плагин CRM, который вызывает службу WCF, служба выдает следующее сообщение об ошибке:CRM Dynamics Вызов службы WCF Ошибка
'The communication object, System.ServiceModel.ChannelFactory`1[ISupplyClaimsService], cannot be modified while it is in the Opening state',
Я также иногда получаем, что при звонке на службу , сработает инструмент регистрации плагинов. Можно ли вызвать службу WCF из плагина? Я вижу некоторые сообщения на нем в Интернете, но никакого конкретного рабочего решения нет, даже в CRM SDK. Мой CRM находится на территории 2013 года, плагин зарегистрирован из изоляции Sandbox (NONE), служба WCF использует именованный домен, а не IP-адрес, его прогоняет HTTP-протокол, см. Мой код ниже. Я выполнил все требования в отношении плагинов и внешних систем, но до сих пор не повезло. Я также протестировал сервис в консольном приложении, SOAP UI работает нормально, только в Плагине у меня возникают проблемы.
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context == null)
{
throw new ArgumentNullException("loaclContext");
}
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity supplyClaimsEntity = (Entity)context.InputParameters["Target"];
if (supplyClaimsEntity.LogicalName != "new_supplierclaimsupdate")
{
return;
}
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
string entityBeginUpload = "Start Upload";
try
{
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Name = "BasicHttpBinding_ISupplyClaimsService";
myBinding.Security.Mode = BasicHttpSecurityMode.None;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endPointAddress = new EndpointAddress(@"http://wmvapps01.tarsus.co.za/SupplyClaimsService.svc");
ChannelFactory<ISupplyClaimsService> factory = new ChannelFactory<ISupplyClaimsService>(myBinding, endPointAddress);
ISupplyClaimsService channel = factory.CreateChannel();
channel.StartApplication();
factory.Close();
}
Обычно этот тип ошибки из-за гонки состояние и многопоточность. Вы сохраняете что-либо в статических переменных в своем плагине? – Daryl
Вы пробовали этот код в консольном приложении? –
Вы также можете добавить инструкцию using, если заводская или поддержка канала IDisposible. – Daryl