Как запросить возможности в Microsoft Dynamics CRM 2011 - PullRequest
0 голосов
/ 15 августа 2011

Я пытаюсь запросить информацию о возможностях из Microsoft Dynamincs CRM 2011.

Есть идеи, почему я продолжаю получать 401 несанкционированную ошибку?

Если я использую URL в браузере, похоже, он работает.

Uri organizationUri = new Uri("/XRMServices/2011/OrganizationData.svc");
Uri homeRealmUri = null;
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password", "domain");
OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
// Get the IOrganizationService
IOrganizationService orgService = (IOrganizationService)orgProxy;
//Get OrganizationServiceContext -the organization service context class implements the IQueryable interface and
//a .NET Language-Integrated Query (LINQ) query provider so we can write LINQ queries against Microsoft Dynamics CRM data.
OrganizationServiceContext orgServiceContext = new OrganizationServiceContext(orgService);

// Get name,number and ownerid for all the account records
var queryAccount1 = from r in orgServiceContext.CreateQuery("opportunity")
                    select new
                    {
                        CustomerID = r["customerid"],
                    };

foreach (var account in queryAccount1)
{
    txtCustomerID.Text = account.CustomerID.ToString();
}

1 Ответ

1 голос
/ 16 августа 2011

Вы получаете доступ к CRM в интрасети или IFD?Я думаю, проблема в том, как вы устанавливаете учетные данные.

Настройка класса NetworkCredential не будет работать, если вы обращаетесь к CRM через IFD

var credentials = new ClientCredentials();
credentials.UserName.UserName = "username";
credentials.UserName.Password = "password";

var organizationUri = new Uri("https://externaluri");
var organizationServiceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
organizationServiceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...