2011-08-15 11 views
0

私は401権限エラーを取得しておく理由は、マイクロソフトDynamincs CRM 2011どのようにMicrosoft Dynamics CRMの中で機会を照会する2011

から任意のアイデアを機会情報を照会しようとしていますか?

ブラウザで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

イントラネットまたはIFDで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()); 
を通して、あなたのCRMにアクセスしている場合NetworkCredentialのクラスを設定する

は動作しません。

関連する問題