locked
CRM 2011: Linq in Plugin RRS feed

  • Question

  • Hello All,

    I am trying to use LINQ in my plugin, I am unable to figure out how to create OrganisationserviceProxy in plugin as it is keep asking for serviceConfiguration...

    IOrganizationServiceFactoryserviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationServiceservice = serviceFactory.CreateOrganizationService(context.UserId);

    OrganizationServiceProxyserviceProxy = (OrganizationServiceProxy)service;

     serviceProxy.EnableProxyTypes();

    ChisServiceContextproxy = newChisServiceContext(service);

    var results = from app in proxy.chis_applicationSet

    join apt in proxy.chis_applicationtimetableSet on app.chis_applicationId equals apt.chis_Application.Id

                                     

    join mod in proxy.chis_moduleSet on apt.chis_Module.Id equals mod.chis_moduleId

                                     

    join modUnit in proxy.chis_chis_module_chis_unitSet on mod.chis_moduleId equals modUnit.chis_moduleid

                                     

    join unit inproxy.chis_unitSet on modUnit.chis_unitid equals unit.chis_unitId

                                     

    join prod in proxy.ProductSet onunit.chis_unitId equals prod.chis_Unit.Id

                                     

    join kit inproxy.ProductSet onmod.chis_moduleId equal skit.chis_Module.Id

                                     

    join rpls inproxy.chis_rplSet onapp.chis_applicationId equals rpls.chis_Application.Id

                                     

    where app.chis_applicationId.Equals(application.chis_applicationId)

                                     

    select new


                                      {

                                          app.chis_applicationId,

                                          app.chis_Funding_Conc,

                                          app.chis_ApplyVTGFund,

                                          apt.chis_applicationtimetableId,

                                          mod.chis_moduleId,

                                          unit.chis_unitId,

                                          prod.ProductId,

                                          prod.chis_VTGPrice,

                                          prod.chis_VTGRPL,

                                          KitProductId = kit.ProductId,

                                          rpls.chis_rplId,

                                          rpls.chis_ApplyRPL

                                      };

    I get invalid cast exception because of not being able to execute EnableProxyType function. If I try to execute this function then I get an exception of "serviceConfiguration is null"


    Hassan




    • Edited by Hassanz Tuesday, April 8, 2014 6:34 AM
    Tuesday, April 8, 2014 6:29 AM

All replies

  • hi,

    in your plugin you can try to

    use     // Obtain the execution context service from the service provider.
    this.PluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    // Obtain the Organization Service factory service from the service provider
    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    // Use the factory to generate the Organization Service.
    OrganizationServiceOrganizationService = factory.CreateOrganizationService(this.PluginExecutionContext.UserId);

    OrganizationServiceProxy serviceProxy = (OrganizationServiceProxy)OrganizationService;
    serviceProxy.EnableProxyTypes();


    Alessandro Graps

    Tuesday, April 8, 2014 9:57 AM
  • Hello Alessandro,

    I was already trying to get ServiceProxy but when executing EnableProxyTypes then an exception of "value is null. Parameter name, serviceConfiguration" occurs.

    Regards,


    Hassan

    Tuesday, April 8, 2014 11:09 PM
  • Hi HAssan

    try this one:

     OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(new Uri("http://win-bvjq2ghxbvn/XRMServices/2011/Organization.svc"),null,cre,null);
    serviceProxy .EnableProxyTypes();

    Bye

    Alessandro


    Alessandro Graps

    Wednesday, April 9, 2014 7:29 AM
  • This two links maybe can explain your problem:

    http://blogs.msdn.com/b/madenwal/archive/2011/03/22/crm-2011-sdk-error-while-using-the-create-method-system-argumentnullexception-value-cannot-be-null.aspx?Redirected=true

    http://nishantrana.wordpress.com/2010/11/03/sample-code-for-using-iorganizationservice-in-crm-2011/

    Bye

    Alessandro


    Alessandro Graps

    Wednesday, April 9, 2014 7:31 AM