1

我正在编写一个应用程序,我必须在其中从 ASP.NET 代码登录到 CRM 2011 服务器。我很快找到了这篇文章:

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

我遇到的问题是那篇文章中的这段代码:

//Create the Service
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.CrmAuthenticationTokenValue = token;
service.Url = crmurl;

Visual Studio 无法解析 CrmService。所以我尝试为这个项目添加一个网络引用,并将网络引用指向我正在使用的 CRM 服务。我从 CRM 中的 Settings->Customizations 获得的 URL,我正在使用组织服务端点。但是,在我添加该引用之后 CrmService 仍然无法解析。我究竟做错了什么?

4

3 回答 3

1

首先,您已经链接了一篇 CRM 4 MSDN 文章,有些事情已经改变,所以您可能想试试这个:使用 Microsoft Dynamics CRM Web 服务验证用户

然后作为替代方案,您可能想尝试CrmConnection该类,它是Microsoft.Xrm.Client. 这意味着您可以使用连接字符串方法向 CRM 进行身份验证(并让班级负责所有繁重的工作)。

var connection = CrmConnection.Parse("Url=http://crm.contoso.com/xrmContoso; Domain=CONTOSO; Username=jsmith; Password=passcode;");
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);

您还可以将连接字符串保留在config文件中,这让生活变得更加轻松。

相关文章:

于 2013-03-07T00:53:41.597 回答
0

If you're using standard AD authentication with a local environment this answer should work fine: How to Authenticate to CRM 2011?

于 2013-03-06T22:22:30.017 回答
0

Actually, the login procedure is heavily dependent on the authentication provider you're targeting. I'm currently in the process of structuring that info in a pedagogic way on my blog so you're welcome to check it out and nag if it's too techy.

There are at the moment four such ways.

  • Active directory
  • Live id
  • Federation
  • Online federation

Which is applicable in your case, you should know already. If not, there's code for that too uploaded just a few days ago.

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
...
public AuthenticationProviderType GetAuthenticationProviderType(Uri address)
{
  IServiceManagement<IOrganizationService> organizationServiceManagement
    = ServiceConfigurationFactory.CreateManagement
      <IOrganizationService>(address);
  return organizationServiceManagement.AuthenticationType;
}

Assuming that you're aiming for AD, you're in luck. It's the easiest.

Uri organizationUrl = new Uri("http ... Organization.svc");
OrganizationServiceProxy organizationService = new OrganizationServiceProxy(
  organizationUrl, null, null, null);

If you're aiming for Live Id - that's stingy. I'm still trying to set up a graspable example. The ones at MSDN are just too heavy and confusing. At least when one's dense and lazy like me. More info at mentioned but undisclosed location.

于 2013-03-06T22:26:01.090 回答