Я пытаюсь запросить информацию о возможностях из 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();
}