I now have a project which needs to build a web portal for Dynamic CRM 2011. I want to use CRM odata service but I cannot go pass windows live authentication in c# code. I also tried to googled some example. Unfortunately, no luck. I am hoping someone who has done this before can tell me how to do it. Thanks too much!
问题:
回答1:
Based on what I have found out, it is no way that I can pass Windows live authentication by code. Therefore, we changed it to Active Directory authentication. Thank you, guys.
回答2:
If you are writing code in C# to communicate with Dynamics 2011 you would be better to use the organization service. The OData endpoint is more suitable for JavaScript code and client-side logic.
The Dynamics CRM 2011 SDK ( https://www.microsoft.com/download/en/details.aspx?id=24004 ) contains examples of how to connect to the service using Windows Live ID. To get started have a look at \samplecode\cs\quickstart once you have downloaded and unzipped the SDK.
回答3:
The OData service is only accessible from code within CRM Online. It's great for javascript inside of CRM (and if that's your need, the CRM 2011 OData Query Designer is wonderfully helpful), but can't be accessed by any code external to the CRM server.
The Microsoft recommended way to access CRM's Web Services is through WCF, as shown in many of the SDK's examples.
If .NET is not an option for you, Srini Raja's answer links to how to access the data using only SOAP.
回答4:
Check your IIS/Authentication settings...
disabled - Anonymous Authentication
enabled - ASP.NET Impersonation
enabled - Windows Authentication
That is required for IIS to pass the user credentials to your web portal. Then you can pass these credentials using the following sample code...
public ActionResult HitCRM()
{
var uri = System.Configuration.ConfigurationManager.AppSettings["CRMURI"];
ClientCredentials credentials = new ClientCredentials();
var dinfo = ServiceConfigurationFactory.CreateConfiguration<IDiscoveryService>(new Uri(uri));
var dsp = new DiscoveryServiceProxy(dinfo, credentials);
dsp.Authenticate();
var retrieveOrganizationsRequest = new RetrieveOrganizationsRequest();
var retrieveOrganizationsResponse = dsp.Execute(retrieveOrganizationsRequest) as RetrieveOrganizationsResponse;
if (retrieveOrganizationsResponse.Details.Count == 1)
{
var organizationDetail = retrieveOrganizationsResponse.Details[0];
Uri orgServiceUri = new Uri(organizationDetail.Endpoints[EndpointType.OrganizationService]);
IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(orgServiceUri);
var creds = new ClientCredentials();
IOrganizationService organizationService = new OrganizationServiceProxy(orgConfigInfo, creds);
Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
var systemUser = organizationService.Retrieve("systemuser", userid, new ColumnSet(new string[] { "firstname", "lastname" }));
// Retrieve the version of Microsoft Dynamics CRM.
var versionRequest = new RetrieveVersionRequest();
var versionResponse = (RetrieveVersionResponse)organizationService.Execute(versionRequest);
ViewBag.FirstName = systemUser.GetAttributeValue<string>("firstname");
ViewBag.LastName = systemUser.GetAttributeValue<string>("lastname");
ViewBag.Version = versionResponse.Version;
}
return View();
}
回答5:
The link below shows windows live authentication as well as getting data from Dynamics CRM 2011 online.
http://blogs.msdn.com/b/girishr/archive/2011/02/04/connecting-to-crm-online-2011-web-services-using-soap-requests-only.aspx
Hope that works for you