Hi I have a CRM 2013 Plugin which calls a WCF service, the service fails with the following error:
'The communication object, System.ServiceModel.ChannelFactory`1[ISupplyClaimsService], cannot be modified while it is in the Opening state',
I also sometimes get that when the call is made to the service, the Plugin Registration tool crashes. Is is possible to call a WCF service from a Plugin? I see some posts on it online, but no concrete working solution is out there, not even in the CRM SDK. My CRM is on-premises 2013, plugin is registered out of Sandbox isolation(NONE), The WCF Service uses a named domain and not an IP address, its runs through HTTP protocol, Please see my code below. I have met all requirements with regards to plugins and external systems, but still no luck. I have also tested the service in a Console application,SOAP UI it works fine, just in the Plugin I am having issues.
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();
}