Hello,
I am writing Plugin on Sales Order Save event which calls WCF service.
I got reference in
http://nishantrana.wordpress.com/2010/11/20/calling-wcf-service-in-plugin-in-crm/
and modified my code and web config.
But now i got error "Object reference not set to an instance of an object"
I debugged and found that i got "Null" in localContext.ServiceProvider.
My code is as below.
protected void ExecuteCRMOrderToAX(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } BasicHttpBinding myBinding = new BasicHttpBinding(); myBinding.Name = "BasicHttpBinding_SalesOrderService"; 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://<<myaxurl>>/MicrosoftDynamicsAXAif50/salesorderservice.svc"); // TODO: Implement your custom Plug-in business logic. var serviceProvider = localContext.ServiceProvider; // Here i m getting serviceProvider as null #region "Passing CRM Credential" ax.SalesOrderServiceClient sc = new ax.SalesOrderServiceClient(myBinding, endPointAddress); sc.ClientCredentials.Windows.ClientCredential.UserName = "crmusername"; sc.ClientCredentials.Windows.ClientCredential.Password = "crmpassword"; sc.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; #endregion #region "Create Sales Order" // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); //getting error because serviceProvider is null
My .config file is as below.
<configuration><configSections></configSections><system.serviceModel><bindings><basicHttpBinding><binding name="BasicHttpBinding_SalesOrderService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"><readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /><security mode="TransportCredentialOnly"><transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" /><message clientCredentialType="UserName" algorithmSuite="Default" /></security></binding></basicHttpBinding></bindings><client><endpoint address="http://<<myaxurl>>/MicrosoftDynamicsAXAif50/salesorderservice.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SalesOrderService" contract="AXServiceReference.SalesOrderService" name="BasicHttpBinding_SalesOrderService" /></client></system.serviceModel></configuration>
Please help.