2016-09-22 19 views
-1

私はCRM on premise 2016に接続してデータを取得するためにこのコードを書いています。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 サーバー:マイクロソフト-IIS/8.5 WWW認証:ネゴシエート WWW認証:NTLM X -Poweredバイ:ASP.NET 接続:キープアライブ のContent-Length:49 のContent-Type:text/plainの }} 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); 
関連する問題