Hi everyone,
Long time no post.
Today I would like to show you guys how to authentication CRM 2011 Online in coding .Net C#.
The objective is: creating a custom web application capturing contact information, then updating the information into CRM Online.
For CRM On Premise, to do so, you guys could follow exactly the same to this blog: http://blogs.msdn.com/b/crminthefield/archive/2011/06/03/microsoft-dynamics-crm-2011-custom-contact-entry-website-using-early-bound-entity-classes.aspx
However, in order to connect to CRM 2011 Online using IOrganizationService Web Service, you need to change the code a bit to make the authentication through (Remember, CRM On Premise using AD authentication, but CRM Online using Windows Live ID to do that).
So please, following the above blog until the code inside and using the below code for CRM Online Authentication:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm;
using Microsoft.Crm.Tools;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Services.Utility;
namespace CRM_Test2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private static ClientCredentials GetDeviceCredentials()
{
return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Authenticate using credentials of the logged in user;
string UserName = "abc@hotmail.sg"; //your Windows Live ID
string Password = "crmadmin@123"; // your password
ClientCredentials Credentials = new ClientCredentials();
Credentials.UserName.UserName = UserName;
Credentials.UserName.Password = Password;
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://<CRM-Online-Server-Name>/XRMServices/2011/Organization.svc"); //this URL could copy from Setting --> Developer Source
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
//Instantiate the contact object and populate the attributes.
Contact contact = new Contact();
contact.FirstName = txtFirstName.Text.ToString();
contact.LastName = txtLastName.Text.ToString();
contact.EMailAddress1 = txtEmailAddress.Text.ToString();
Guid newContactId = service.Create(contact);
//This code will clear the textboxes after the contact is created.
txtFirstName.Text = "";
txtLastName.Text = "";
txtEmailAddress.Text = "";
txtPhoneNumber.Text = "";
}
}
}
}
Notice the red lines in above code. That's the difference between authenticate in CRM Online and On Premise. For Online version, you need to call the function named "GetDeviceCredentials()", which is defined as private function before that. In order to use this function, you MUST to add one more item which is from SDK --> SampleCode --> Cs --> deviceidmanager.cs. So add this new item into your solution.
After adding the deviceidmanager.cs item, open the cs file and add one more nesscessary reference for using the item, which is: System.Security.Cryptography.
Then now build the whole solution ! Everything is done !
Any question or unclear point. Please drop me an email at linhhk87@gmail.com. I will reply you very quick ;)
Have a nice weekend ;)
Long time no post.
Today I would like to show you guys how to authentication CRM 2011 Online in coding .Net C#.
The objective is: creating a custom web application capturing contact information, then updating the information into CRM Online.
For CRM On Premise, to do so, you guys could follow exactly the same to this blog: http://blogs.msdn.com/b/crminthefield/archive/2011/06/03/microsoft-dynamics-crm-2011-custom-contact-entry-website-using-early-bound-entity-classes.aspx
However, in order to connect to CRM 2011 Online using IOrganizationService Web Service, you need to change the code a bit to make the authentication through (Remember, CRM On Premise using AD authentication, but CRM Online using Windows Live ID to do that).
So please, following the above blog until the code inside and using the below code for CRM Online Authentication:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm;
using Microsoft.Crm.Tools;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Services.Utility;
namespace CRM_Test2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private static ClientCredentials GetDeviceCredentials()
{
return Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
}
protected void Button1_Click(object sender, EventArgs e)
{
//Authenticate using credentials of the logged in user;
string UserName = "abc@hotmail.sg"; //your Windows Live ID
string Password = "crmadmin@123"; // your password
ClientCredentials Credentials = new ClientCredentials();
Credentials.UserName.UserName = UserName;
Credentials.UserName.Password = Password;
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://<CRM-Online-Server-Name>/XRMServices/2011/Organization.svc"); //this URL could copy from Setting --> Developer Source
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, GetDeviceCredentials()))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
//Instantiate the contact object and populate the attributes.
Contact contact = new Contact();
contact.FirstName = txtFirstName.Text.ToString();
contact.LastName = txtLastName.Text.ToString();
contact.EMailAddress1 = txtEmailAddress.Text.ToString();
Guid newContactId = service.Create(contact);
//This code will clear the textboxes after the contact is created.
txtFirstName.Text = "";
txtLastName.Text = "";
txtEmailAddress.Text = "";
txtPhoneNumber.Text = "";
}
}
}
}
Notice the red lines in above code. That's the difference between authenticate in CRM Online and On Premise. For Online version, you need to call the function named "GetDeviceCredentials()", which is defined as private function before that. In order to use this function, you MUST to add one more item which is from SDK --> SampleCode --> Cs --> deviceidmanager.cs. So add this new item into your solution.
After adding the deviceidmanager.cs item, open the cs file and add one more nesscessary reference for using the item, which is: System.Security.Cryptography.
Then now build the whole solution ! Everything is done !
Any question or unclear point. Please drop me an email at linhhk87@gmail.com. I will reply you very quick ;)
Have a nice weekend ;)
Thank you so much for this review! I found it very helpful, this seem like a program that would be of great use to me. Keep it up!
ReplyDeleteArabia Interactive - Web Design Dubai
Hi, thanks for your comment. Merry Xmas & Happy New Year :)
ReplyDeleteI could not run, I mark that is not the library and not Microsoft.Crm.Services.Utility Contact (), how I can fix this, I would appreciate a prompt response
ReplyDeleteI read your all contain it is very helpful for your service , find some information related custom web applications
ReplyDeleteHi kelly,
ReplyDeleteI am doing this from my local machine (Windows 7 Os). I have Asp.net website and did the same what you have mentioned above. But while running i m getting this error.
The authentication endpoint Username was not found on the configured Secure Token Service!".
I m connecting online CRM and added 'DeviceId" class from helper code to my website.
It was very helpful. Thanks.
ReplyDeleteHi,
ReplyDeleteI've done everything that you said in the article and then deployed it to my web host. It complains that it cant find the microsoftidentitymodel assembly
I've now asked my provider if they can install this for me (as I dont have the rights to install it it) - failing that is there anything I can do to get around this (a different way of connecting to an online instance from a web sever - not localhost)?
Thanks.
Pinga solutions is the no 1 software providing company in Delhi Ncr that's providing online CRM software, payment collection software, Construction management software, construction erp with affordable price.Customer can choose and purchase online crm software,real estate software,payment collection software,Construction management software etc.
ReplyDeleteOnline CRM Software
Acetech Software should be your first choice if you are looking for a software development company Delhi India for your web designing need.
ReplyDeleteThe code is also suitable for on-premise after setup claims-based authentication (IFD).
ReplyDeleteThanks. you saved me a lot of time.
Great article and interesting discovery about computer services.
ReplyDeleteWindows Thin Client & Zero Clients
Great blog. When i loved this completely.
ReplyDeleteDynamic Website Development Company & Website Design Company Delhi
Great stuff dear. I like it Thin Clients & Zero Clients
ReplyDeleteThis is a really good read for me, Must admit that you are one of the best bloggers I ever saw.
ReplyDeleteDigital Graphic Design & Company Profile Design
i just wanna thank you for sharing your information and your site or blog this is simple but nice article I've ever seen i like it i learn something today...
ReplyDeletepay per click agency & online marketing company
Very Nice blog. I am really happy while reading it.
ReplyDeleteWell the code you have written in ASP.Net is really helpful and I haven’t tried it so I look forward to it. I will ask query because I am learning .Net now a days and it is very powerful language.
ReplyDeleteSoftware for real estate agents
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.
ReplyDeletesearch Engine Optimization services in Mumbai & Social Media Optimization Company in Mumbai
Best content is in this site.Thanks for sharing for great resources.
ReplyDeleteCustom Application Development Services
Even it took some time to me read all the opinions but I truly enjoyed and also got impressed by these posts.It turned out to be very useful to me and I am sure to all the posters who post their comments here, It’s wonderful when you are not only informed, but also entertained during going through these posts.
ReplyDelete視覺設計
It gives a robust tool for handling all the activities of a business.....
ReplyDeleteCRM Software for Real Estate Agents
This software works on a common goal to enable your sales and marketing....
ReplyDeleteCRM Solutions Real Estate Developers
Very good information, it will help us alot.
ReplyDeleteCustom Web Application Development Company
Web Development Company
This information is impressive; I am inspired with your post writing style & how continuously you.
ReplyDeleteWeb Development Dubai
Thank you so much for this review! I found it very helpful, this seem like a program that would be of great use to me. Keep it up! web designer Dubai
ReplyDeleteThe blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents...Great job, keep it up..Web Designing Company Bangalore | Website Design Company Bangalore
ReplyDeleteThanks for nice article about web application development services.
ReplyDeleteWeb Application Development Services
good one, im waiting for more articlest like this. keep up the good work.
ReplyDeleteSEO Dubai
Nice Information thank you for Sharing useful information.
ReplyDeleteCustom Web Application Development
Thanks for this worth reading post. I really enjoyed it and surely will also recommend others.
ReplyDeleteSEO Sharjah
Your blog is great and now I have become a regular visitor of your blog. I appreciate the good work.
ReplyDeletePublic Relation company in Dubai
outsourcingall.com "Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it.
ReplyDeleteThis paragraph gives clear idea for the new viewers of blogging, Thanks you. You’re doing a great job Man, Keep it up.
outsourcing training in dhaka
Thank you for providing a wonderful article. It is a great guide for me. Please share more articles like this.
ReplyDeleteSplendid post. Also visit here: Feeta.pk - property for sale in islamabad . it is very helpful for us thanks for sharing.
ReplyDelete