Thursday, September 29, 2011

CRM online 2011 with Odata and WCF

Hi guys, I have strugled a lot with working on CRM 2011 online. It has killed my two day's. Oh!!  It might be beacause of my low brain or subject :) :)
Any how I am able to manage to get data from CRM 2011 online.  In my previous blog, I have explained about basics about CRM 2011.

Now, I am going to explain how do we access CRM 2011 online data using services.

CRM 2011 Online


1. Register for CRM 2011 Online using Windows Live ID.
You can get it here: http://crm.dynamics.com/en-us/home

Available services in CRM 2011.

CRM can allow multiple Organizations to be created on 1 CRM installation.

Each Organization can be for a different company/purpose. So, users may want to access one of the Organizations on CRM installation. If the user/code already knows the Organization URL OR Organization Service URL then fine he can directly use organization service.

If not known, then he needs to write code to connect Discovery Service URL, then browse through all Organizations available and get Organization service URL for respective/required Organization.
In short, whatever Data/Metadata operations we want to do, we will need to use Organization Service URL.
If we want to find Organization Service URL for an Organization, then we need to do that using Discovery Service URL.

https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc (North America)


https://dev.crm4.dynamics.com/XRMServices/2011/Discovery.svc (EMEA)


https://dev.crm5.dynamics.com/XRMServices/2011/Discovery.svc (APAC)


The following URLs should be used to access the Organization service(SOAP endpoint):


https://{Organization Name}.api.crm.dynamics.com/XrmServices/2011/Organization.svc (North America)

https://{Organization Name}.api.crm4.dynamics.com/XrmServices/2011/Organization.svc (EMEA)

https://{Organization Name}.api.crm5.dynamics.com/XrmServices/2011/Organization.svc (APAC)

Where {Organization Name} refers to the Organization that you specify in the URL when accessing the Web application. For example, for Contoso.crm.dynamics.com, the {Organization Name} is Contoso.

The following URLs should be used to access the Organization Data service(OData REST endpoint)

https://{Organization Name}.api.crm.dynamics.com/XrmServices/2011/OrganizationData.svc (North America)


https://{Organization Name}.api.crm4.dynamics.com/XrmServices/2011/OrganizationData.svc (EMEA)


https://{Organization Name}.api.crm5.dynamics.com/XrmServices/2011/OrganizationData.svc (APAC)



For CRM On-premises customers:



http://{server}/XRMServices/2011/Discovery.svc for the Discovery service endpoint


http://{server}/{OrgName}/XRMServices/2011/Organization.svc for the Organization Service endpoint (SOAP)


http://{server}/{OrgName}/XRMServices/2011/OrganizationData.svc for the Organization Data Service endpoint (REST)


http://{server}/XRMDeployment/2011/Deployment.svc for the Deployment Service endpoint



2.Install Microsoft Dynamics CRM 2011 SDK.

You can get it here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=eb9c345f-e830-40b8-a5fe-ae7a864c4d76&displaylang=en

3. Run the DeviceRegistration.exe utility to generate a device id and password.

There are two methods to get device id and password.

1.Using DiviceMAnager class available in SDK folder. So that we can generate device id and password.

2.By Commandline.

Once you download SDK from above given link, Inside tools, there will deviceregistration directory. Run it with command line /operation:Register.

Then you will get device id and password. Copy these credentials for further use.

4.Making context class for the organization.svc or discovery service.

C:\Users\aravinda.sheshadri\Desktop\ToolkitGestureDemo\sdk\bin\crmsvcutil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /url:https://<>.crm5.dynamics.com/XRMServices/2011/Organization.svc /o:crm.cs /n:XXXCRM2011 /domain:<>.crm5.dynamics.com /u:<> /p:<>/serviceContextName:XXXcontext /di:116bohmbs2iupfaxp07bp5mhrp /dp:GYfG8LSo%_+3H2H+mpT~w=IG

On run this command, class will be generated containing all entities(context). Here, I have given context name as XXXcontext. So I can access all entities using XXXcontext name.

While running this command, make sure that time in both server and local machine will be same(Time and Timezone).

5. Add this class file to your visual studio 2010 project.



6.Add a reference to the dll’s in there as necessary from SDK folder bin directory:



Microsoft.XRM.sdk

System.ServiceModel

Microsoft.Crm.Sdk.Data.Services;

System.Data.Services.Client;

System.ServiceModel.Description;

Microsoft.Xrm.Sdk;

Microsoft.Xrm.Sdk.Client;

Microsoft.Crm.Services.Utility;

7. How do I access CRM 2011 online wcf service over .net client?



If we are using organization.svc, then we have to use



OrganizationServiceProxy _serviceProxy;

IOrganizationService _service;

ClientCredentials Credentials = new ClientCredentials();

ClientCredentials devivceCredentials = new ClientCredentials();

CRMContext context;



Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;



//This URL needs to be updated to match the servername and Organization for the environment.





Uri OrganizationUri = new Uri("https://{organization name}.crm5.dynamics.com/XRMServices/2011/Organization.svc");



Uri HomeRealmUri = null;



//To get device id and password.



devivceCredentials= DeviceIdManager.LoadDeviceCredentials();





using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, devivceCredentials))

{

serviceProxy.ClientCredentials.UserName.UserName = "username";

serviceProxy.ClientCredentials.UserName.Password = "password";

serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

IOrganizationService service = (IOrganizationService)serviceProxy;

_service = (IOrganizationService)serviceProxy;

context = new CRMContext(_service);

var querry = context.CreateQuery("LeadSet");

var querry1 = from itm in context.LeadSet

select itm;





}


8. Odata(OrganizatationData.svc) is not supported outside the CRM application.

Currently CRM 2011 does not support for Odata(organizationdata.svc) to do any operation from outside the CRM application. So If we make it as web resources, then we can use Odata services.







Proof:

http://mscrmblogger.com/2011/05/12/crm-2011-supported-vs-unsupported/
http://mscrmblogger.com/2011/05/12/crm-2011-supported-vs-unsupported/

http://msdn.microsoft.com/en-us/library/gg334279.aspx

“The REST Endpoint for Web resources provides an alternative interface to work with Microsoft Dynamics CRM data. You can use the REST endpoint to execute HTTP requests by using a service that is based on a Uniform Resource Identifier (URI). The REST endpoint is only available for use by JScript and Silverlight Web resources.”

Thanks


Aravind
aravindbenator@gmail.com



Thursday, September 22, 2011

jQuery Mobile.- Play with jQuery (if you you do not know javascript also!!.)





JQuery Mobile (Alpha 2.0).

Introduction
o jQuery Mobile, a user interface (UI) framework to write a functional mobile web application without writing a single line of JavaScript code.

jQuery Mobile

o jQuery Mobile is a touch-friendly web UI development framework that allows to develop mobile web applications that work across smartphones and tablets. The jQuery Mobile framework builds on top of jQuery core and provides a number of facilities, including HTML and XML document object model (DOM) traversing and manipulation, handling events, performing server communication using Ajax, as well as animation and image effects for web pages. The mobile framework itself is a separate, additional download of around 12KB (minified and gzipped) from jQuery core, which is around 25KB when minified/gzipped. As with the rest of the jQuery framework, jQuery Mobile is a free, dual-licensed (MIT and GPL) library.
Downloads available @
o http://www.ibm.com/developerworks/web/library/wa-jqmobile/#download
o http://www.ibm.com/developerworks/web/library/wa-jqmobile/


Basic features of jQuery Mobile include:
General simplicity
o The framework is simple to use. We can develop pages mainly using markup driven with minimal or no JavaScript.

Progressive enhancement and graceful degradation
o While jQuery Mobile leverages the latest HTML5, CSS3, and JavaScript, not all mobile devices provide such support.


Accessibility
o jQuery Mobile is designed with accessibility in mind. It has support for Accessible Rich Internet Applications (WAI-ARIA) to help make web pages accessible for visitors with disabilities using assistive technologies.
Small size
o The overall size of the jQuery Mobile framework is relatively small at 12KB for the JavaScript library, 6KB for the CSS, plus some icons.
Theming
o The framework also provides a theme system that allows us to provide our own application styling.


Browser support
o Not all mobile devices provide support for HTML5, CSS 3, and JavaScript.
o jQuery Mobile currently provides support for the following mobile platforms:
o Apple® iOS: iPhone, iPod Touch, iPad (all versions)
o Android™: all devices (all versions)
o Blackberry® Torch (version 6)
o Palm™ WebOS Pre, Pixi
o Nokia® N900 (in progress)

Structure of a jQuery Mobile page
o jQuery Mobile has guidelines on the structure of pages themselves. In general, a page structure should have the following sections:
Header bar
o Typically contains the page title and Back button
Content
o The content of your application
Footer bar
o Typically contains navigational elements, copyright information, or whatever you need to add to the footer



Example:


HTML head section
o

o attributes that are telling jQuery Mobile what this element is, how to look like and how to behave.





Defining a page block:
o

Page header bar section:
o

Page content section:
o

Footer bar section:

o

Adding a nav bar to the footer section:

o

Defining multiple local pages

o jQuery Mobile also provides support for multiple pages within a single HTML document. The multiple pages are local, internal linked "pages" that we can group together for preloading purposes. The structure of the multipage page is similar to the previous example of a single page, except that it will contain multiple page data-roles. Listing 8 shows an example.

o

Page transitions:
o jQuery Mobile provides support for CSS-based page transitions (inspired by jQtouch), which are applied when navigating to a new page and back. The transitions include:
Slide
o Provides a horizontal transition
Slide up and Slide down
o Provide transitions up and down the screen
Pop
o Provides an explode type of transition
Fade
o Provides a fading transition
Flip
o Provides a flip transition

o We can add page transitions in two different ways:
o Add a data-transition attribute to the link, using
o Use the data-transition attribute on static pages.
o Programmatically, using $.mobile.changePage("pendingtasks.html", "slideup");
o Use the programmatic approach when working with dynamic pages.

List views
o List views, a fundamental type of UI element, are heavily used in mobile applications. jQuery Mobile supports numerous list views: basic, nested, numbered, and read-only lists; split buttons; list dividers; count bubbles; thumbnails; icons; search filter bars; inset styled lists; and theming lists.
o A list view is created by using the

    data attribute. o o Inside the
      we define common
    • list items.

      Forms
      o Forms are used to post information to a server. jQuery Mobile supports many form UI components: text inputs, search inputs, slider, flip toggle switch, radio buttons, checkboxes, select menus, and theming forms.
      o Select menus are driven by native

Friday, September 2, 2011

Shedding light over CLR..

Common Language Runtime (CLR) is the engine available in .Net Framework to compile and run the program. CLR engine does not compile the code in machine code but converts the code in a set of instructions called Microsoft Intermediate Language (MSIL). This MSIL is one of the section of Portable Executable (PE) file, the other being Metadata. PE file automatically get generated when you compile the program code.




The conversion of the program code to MSIL by CLR engine, makes .Net platform and language independent. Although at present, Microsoft does not have CLR engines for other platforms, in future you can find .Net application being compiled in UNIX or Linux operating system. After the conversion of the program code to MSIL, the code is then translated to native or machine code. Instead of compiling the program code at development time, the MSIL code gets translated ‘just in time’ (JIT) by JIT compilers.




There are currently over 15 compilers being built by Microsoft and other companies that produce code that will execute in the CLR. CLR engine is divided into modules that contain code, metadata, and resources. The code is stored in common intermediate language (CIL) format. The module's metadata includes the types such as names, inheritance relationships, method signatures, and dependency information. The module's resources consist of static read-only data such as strings, bitmaps, and other aspects of the program that are not stored as executable code.



The CLR supports component-based programming. Component development has numerous attractive benefits such as code reuse, proper maintenance of all components by allowing independent bug fixes to each. In addition, the CLR helps developers in managing both allocation and deallocation of memory. This removes two of the largest sources of programmer error: leaks and memory corruption.



CLR is also helpful for security purposes. CLR provide permissions to a component based on what process it runs in, validates the code based on evidence such as information about code at load time and the website from which component was obtained to assign permissions on a component-by-component basis. Moreover, CLR checks the code to see if it has been manipulated. The metadata in a CLR component can contain a digital signature that can be used to verify that the component was written by genuine person and that it has not been modified. You can verily identify if anyone has tried to modify with the code. For example, if someone tries to change the code of transferring money from the intended recipient to himself the CLR will prevent the altered code from running.