2016-09-22 2 views
-1

전제 CRM 20에 연결하고 일부 데이터를 검색하려면이 코드를 작성했습니다. 여기CRM 2016 api 무단 액세스

var credentials = new NetworkCredential("username", "password?", "domain"); 
      var client = new HttpClient(new HttpClientHandler() { Credentials = credentials }) 
      { 
       BaseAddress = new Uri("https://xxxtestenv.elluciancrmrecruit.com/api/data/v8.0/") 
      }; 
      client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 
      var response = client.GetAsync("datatel_events?$orderby=datatel_eventname").Result; 
      if (response.IsSuccessStatusCode) 
      { 
       var yourcustomobjects = response.Content.ReadAsStringAsync(); 
      } 

이다 그러나 나는이 오류를

response {StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: 

{ REQ_ID를 얻을 : b685b007-199b-4a4a-85cc-3a29684e5588 날짜 : 2016년 9월 22일 (목) 19 : 27:35 GMT 서버 : Microsoft-IIS/8.5 WWW- 인증 : 협상 WWW- 인증 : NTLM X -Powered - 작성자 : ASP.NET 연결 : 연결 유지 콘텐츠 길이 : 49 콘텐츠 유형 : 텍스트/일반 }} System.Net.Http.HttpResponseMessage

어떤 제안?

+0

IFD를 사용할 수 있습니까? –

+0

예, 어디서나 액세스 할 수 있습니다. 나는 httpclient가 crm에 로그인하는 데 사용하는 다른 링크로 연결되는 링크를 리디렉션하는 코드를 디버깅 할 때 발견했습니다. 이 말은 정상적으로 들리니? –

답변

0

아래 코드를 사용하여 MS CRM 온 프레미스에 연결하십시오.

string strOrganizationUri = "https://{your domain}/XRMServices/2011/Organization.svc"; 
      string strUserName = "{your domain username}"; 
      string strPassword = "{your domain password}"; 
      var organizationUriIFD = new Uri(strOrganizationUri); 

      var credentials = new ClientCredentials(); 
      credentials.UserName.UserName = strUserName; 
      credentials.UserName.Password = strPassword; 

      IServiceConfiguration<IOrganizationService> config = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(organizationUriIFD); 
      IOrganizationService service; 
      using (var serviceProxy = new OrganizationServiceProxy(config, credentials)) 
      { 
       // This statement is required to enable early-bound type support. 
       serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); 

       service = serviceProxy; 

      } 


      // Get the ID's of the current user and business unit. 
      var who = new WhoAmIRequest(); 
      //retreive user data from the server. 
      var whoResponse = (WhoAmIResponse)service.Execute(who); 
관련 문제