locked
Accessing CRM 2011 service in .net 3.5 framework application RRS feed

  • Question

  • Hi All,

    I'm trying to create a custom web part in sharepoint 2010 where i wanted to check whether logged in user has got proper role privilages to create a new entity or has proper access rights to edit a existing records

    till now with all googling what i could find for this was using CRM 2011 SDK since in my scenario i can not use SDK due to dependency on framework 4.0.

    Kindly guide me how i can achieve the same without taking help of methods provided in SDK 

     


    Best Regards, Ashutosh | SharePoint World
    Monday, January 16, 2012 11:48 AM

Answers

  • It is possible to do this via WCF in .Net 3.5. With WCF you get an OrganizationServiceClient instance, which implements IOrganizationService, and hence gives you access to the messages and methods documented in the CRM SDK.

    One major issue with CRM Online relates to how you get the token. There is some example code in the SDK, but you'll need to change the AppliesTo constants - see http://mscrmuk.blogspot.com/2012/01/using-wsdl-proxies-with-crm-online-its.html


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk


    Friday, February 10, 2012 10:18 PM
    Moderator
  • This is code to get Organization Service for 3.5. Do not forget to add service reference for needed organization service(http://<servername>:<portnumber>/<organizationname>/XRMServices/2011/Organization.svc?wsdl). I use it for developing SSIS packages for SQL Server 2008.

     Uri orgURL = new Uri (stringURL);
    
    
                SymmetricSecurityBindingElement security = SecurityBindingElement.CreateSspiNegotiationBindingElement();
                security.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Default;
                security.SecurityHeaderLayout = SecurityHeaderLayout.Strict;
                security.IncludeTimestamp = true;
                security.KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy;
                security.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature;
                security.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
                security.LocalClientSettings.CacheCookies = true;
                security.LocalClientSettings.DetectReplays = true;
                security.LocalClientSettings.ReplayCacheSize = 900000;
                security.LocalClientSettings.MaxClockSkew = new TimeSpan(0, 5, 0);
                security.LocalClientSettings.MaxCookieCachingTime = new TimeSpan(23, 0, 0, 0);
                security.LocalClientSettings.ReplayWindow = new TimeSpan(0, 5, 0);
                security.LocalClientSettings.SessionKeyRenewalInterval = new TimeSpan(15, 0, 0);
                security.LocalClientSettings.SessionKeyRolloverInterval = new TimeSpan(0, 5, 0);
                security.LocalClientSettings.ReconnectTransportOnFailure = true;
                security.LocalClientSettings.TimestampValidityDuration = new TimeSpan(0, 5, 0);
                security.LocalClientSettings.CookieRenewalThresholdPercentage = 60;
                security.LocalServiceSettings.DetectReplays = true;
                security.LocalServiceSettings.IssuedCookieLifetime = new TimeSpan(10, 0, 0);
                security.LocalServiceSettings.MaxStatefulNegotiations = 128;
                security.LocalServiceSettings.ReplayCacheSize = 900000;
                security.LocalServiceSettings.MaxClockSkew = new TimeSpan(0, 5, 0);
                security.LocalServiceSettings.NegotiationTimeout = new TimeSpan(0, 1, 0);
                security.LocalServiceSettings.ReplayWindow = new TimeSpan(0, 5, 0);
                security.LocalServiceSettings.InactivityTimeout = new TimeSpan(0, 2, 0);
                security.LocalServiceSettings.SessionKeyRenewalInterval = new TimeSpan(15, 0, 0);
                security.LocalServiceSettings.SessionKeyRolloverInterval = new TimeSpan(0, 5, 0);
                security.LocalServiceSettings.ReconnectTransportOnFailure = true;
                security.LocalServiceSettings.MaxPendingSessions = 128;
                security.LocalServiceSettings.MaxCachedCookies = 1000;
                security.LocalServiceSettings.TimestampValidityDuration = new TimeSpan(0, 5, 0);
    
                TextMessageEncodingBindingElement textEncoding = new TextMessageEncodingBindingElement();
                textEncoding.MaxReadPoolSize = 64;
                textEncoding.MaxWritePoolSize = 16;
                textEncoding.MessageVersion = MessageVersion.Default;
                textEncoding.WriteEncoding = System.Text.Encoding.UTF8;
                    
                
    
                HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
                httpTransport.ManualAddressing = false;
                httpTransport.MaxBufferSize = 65536;
                httpTransport.MaxReceivedMessageSize = 65536;
                httpTransport.AllowCookies = false;
                httpTransport.AuthenticationScheme = AuthenticationSchemes.Anonymous;
                httpTransport.BypassProxyOnLocal = false;
                httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                httpTransport.KeepAliveEnabled = true;
                httpTransport.MaxBufferPoolSize = 524288;
                httpTransport.ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous;
                httpTransport.TransferMode = TransferMode.Buffered;
                httpTransport.UnsafeConnectionNtlmAuthentication = false;
                httpTransport.UseDefaultWebProxy = true;
                
    
                CustomBinding binding = new CustomBinding(new List<BindingElement> { security, textEncoding, httpTransport });
                EndpointAddress endpoint = new EndpointAddress(orgURL);
    
                OrganizationServiceClient client = new OrganizationServiceClient(binding, endpoint);
    
               
                
                
                
                IOrganizationService _orgservice = (IOrganizationService) client;


    • Edited by gmaly Thursday, July 19, 2012 10:44 AM
    • Proposed as answer by gmaly Thursday, July 19, 2012 2:46 PM
    • Marked as answer by Andrii ButenkoMVP, Moderator Thursday, July 19, 2012 2:55 PM
    Thursday, July 19, 2012 10:41 AM

All replies

  • Hi Ashutosh,

     if you dont want to use SDK to query for User previlage 

     you can use Filteredview to   query  for the User Role

     hth

    dkay

     if the response answered your question, please take a minute and mark the response as an answer.

    Monday, January 16, 2012 12:48 PM
  • Hi it would be great if you can provide me some sample code or a good link to which i can refer
    Best Regards, Ashutosh | SharePoint World
    Monday, January 16, 2012 1:04 PM
  • Please find the article which describe where CRM store the Users privileges

    You can query these Filtered view with normal SQL query as  you would do on the table.

    http://blogs.msdn.com/b/crm/archive/2009/08/04/viewing-all-crm-privileges-including-hidden-privileges.aspx

    hth

    dkay

     if the response answered your question, please take a minute and mark the response as an answer.

    Monday, January 16, 2012 1:23 PM
  • hi the post you have sent refers to CRM 4. I know how to do it in CRM 4 i wanted to achieve the same using CRM 2011 services and in .net framework 3.5 compatible application
    Best Regards, Ashutosh | SharePoint World
    Monday, January 16, 2012 1:30 PM
  • Most of the these table structure / definition still applies for crm 2011

     

    Monday, January 16, 2012 1:32 PM
  • I had look at the code and its using reporting services and SQL. I wanted to keep it simple is thier any way to get it done using WCF services exposed by crm 2011
    Best Regards, Ashutosh | SharePoint World
    Monday, January 16, 2012 1:40 PM
  • Hi Astutosh,

    I dont think that there can be anything much simpler than writing a SQL SELECT again an Filtered view the output would be a datatable

    Its sames as writing SQL Statement against TABLE

    If need  help on  Filtered view , writting SQL statement and ADO.NET to access Datatable

    just google it  you would find plenty of examples.

    hth

    dkay

     if the response answered your question, please take a minute and mark the response as an answer.

     

     

    Monday, January 16, 2012 2:55 PM
  • Hi

    Did this help?

    Please make sure to mark as answer to the response that helped you get through. This will help others with similar problem identify the answer and also close this thread as resolved.

    Thanks

    Dkay

    Monday, January 16, 2012 9:43 PM
  • i would like to know if we can do this via WCF Service or not ? as i need solution which works well with CRM online and inpremise CRM both.
    Best Regards, Ashutosh | SharePoint World
    Tuesday, January 17, 2012 5:03 AM
  • It is possible to do this via WCF in .Net 3.5. With WCF you get an OrganizationServiceClient instance, which implements IOrganizationService, and hence gives you access to the messages and methods documented in the CRM SDK.

    One major issue with CRM Online relates to how you get the token. There is some example code in the SDK, but you'll need to change the AppliesTo constants - see http://mscrmuk.blogspot.com/2012/01/using-wsdl-proxies-with-crm-online-its.html


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk


    Friday, February 10, 2012 10:18 PM
    Moderator
  • This is code to get Organization Service for 3.5. Do not forget to add service reference for needed organization service(http://<servername>:<portnumber>/<organizationname>/XRMServices/2011/Organization.svc?wsdl). I use it for developing SSIS packages for SQL Server 2008.

     Uri orgURL = new Uri (stringURL);
    
    
                SymmetricSecurityBindingElement security = SecurityBindingElement.CreateSspiNegotiationBindingElement();
                security.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Default;
                security.SecurityHeaderLayout = SecurityHeaderLayout.Strict;
                security.IncludeTimestamp = true;
                security.KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy;
                security.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature;
                security.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
                security.LocalClientSettings.CacheCookies = true;
                security.LocalClientSettings.DetectReplays = true;
                security.LocalClientSettings.ReplayCacheSize = 900000;
                security.LocalClientSettings.MaxClockSkew = new TimeSpan(0, 5, 0);
                security.LocalClientSettings.MaxCookieCachingTime = new TimeSpan(23, 0, 0, 0);
                security.LocalClientSettings.ReplayWindow = new TimeSpan(0, 5, 0);
                security.LocalClientSettings.SessionKeyRenewalInterval = new TimeSpan(15, 0, 0);
                security.LocalClientSettings.SessionKeyRolloverInterval = new TimeSpan(0, 5, 0);
                security.LocalClientSettings.ReconnectTransportOnFailure = true;
                security.LocalClientSettings.TimestampValidityDuration = new TimeSpan(0, 5, 0);
                security.LocalClientSettings.CookieRenewalThresholdPercentage = 60;
                security.LocalServiceSettings.DetectReplays = true;
                security.LocalServiceSettings.IssuedCookieLifetime = new TimeSpan(10, 0, 0);
                security.LocalServiceSettings.MaxStatefulNegotiations = 128;
                security.LocalServiceSettings.ReplayCacheSize = 900000;
                security.LocalServiceSettings.MaxClockSkew = new TimeSpan(0, 5, 0);
                security.LocalServiceSettings.NegotiationTimeout = new TimeSpan(0, 1, 0);
                security.LocalServiceSettings.ReplayWindow = new TimeSpan(0, 5, 0);
                security.LocalServiceSettings.InactivityTimeout = new TimeSpan(0, 2, 0);
                security.LocalServiceSettings.SessionKeyRenewalInterval = new TimeSpan(15, 0, 0);
                security.LocalServiceSettings.SessionKeyRolloverInterval = new TimeSpan(0, 5, 0);
                security.LocalServiceSettings.ReconnectTransportOnFailure = true;
                security.LocalServiceSettings.MaxPendingSessions = 128;
                security.LocalServiceSettings.MaxCachedCookies = 1000;
                security.LocalServiceSettings.TimestampValidityDuration = new TimeSpan(0, 5, 0);
    
                TextMessageEncodingBindingElement textEncoding = new TextMessageEncodingBindingElement();
                textEncoding.MaxReadPoolSize = 64;
                textEncoding.MaxWritePoolSize = 16;
                textEncoding.MessageVersion = MessageVersion.Default;
                textEncoding.WriteEncoding = System.Text.Encoding.UTF8;
                    
                
    
                HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
                httpTransport.ManualAddressing = false;
                httpTransport.MaxBufferSize = 65536;
                httpTransport.MaxReceivedMessageSize = 65536;
                httpTransport.AllowCookies = false;
                httpTransport.AuthenticationScheme = AuthenticationSchemes.Anonymous;
                httpTransport.BypassProxyOnLocal = false;
                httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                httpTransport.KeepAliveEnabled = true;
                httpTransport.MaxBufferPoolSize = 524288;
                httpTransport.ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous;
                httpTransport.TransferMode = TransferMode.Buffered;
                httpTransport.UnsafeConnectionNtlmAuthentication = false;
                httpTransport.UseDefaultWebProxy = true;
                
    
                CustomBinding binding = new CustomBinding(new List<BindingElement> { security, textEncoding, httpTransport });
                EndpointAddress endpoint = new EndpointAddress(orgURL);
    
                OrganizationServiceClient client = new OrganizationServiceClient(binding, endpoint);
    
               
                
                
                
                IOrganizationService _orgservice = (IOrganizationService) client;


    • Edited by gmaly Thursday, July 19, 2012 10:44 AM
    • Proposed as answer by gmaly Thursday, July 19, 2012 2:46 PM
    • Marked as answer by Andrii ButenkoMVP, Moderator Thursday, July 19, 2012 2:55 PM
    Thursday, July 19, 2012 10:41 AM