0

使用Windows驗證可以使用Simple Odata Client請求我的Odata服務(由Asp.Net MVC託管)?使用Windows驗證的Simple.Odata客戶端

簡單的OData客戶需要憑據:

public ODataClient(ODataClientSettings settings); 
public ODataClientSettings(Uri baseUri, ICredentials credentials = null); 

,我發現的唯一例子是基於newtworkCredentials: https://github.com/object/Simple.OData.Client/blob/master/Simple.OData.Client.IntegrationTests/WebApiTests.cs

public class WebApiWithAuthenticationTests : WebApiTestsBase 
{ 
    private const string _user = "tester"; 
    private const string _password = "tester123"; 

    public WebApiWithAuthenticationTests() 
     : base(new ODataClientSettings() 
     { 
      BaseUri = new Uri("http://va-odata-integration.azurewebsites.net/odata/secure"), 
      Credentials = new NetworkCredential(_user, _password) 
     }) 
    { 
    } 
} 

回答

0

嘗試使用CredentialCache.DefaultCredentials屬性這樣。

public class WebApiWithAuthenticationTests : WebApiTestsBase 
{  
    public WebApiWithAuthenticationTests() 
     : base(new ODataClientSettings() 
     { 
      BaseUri = new Uri("http://va-odata-integration.azurewebsites.net/odata/secure"), 
      Credentials = CredentialCache.DefaultCredentials 
     }) 
    { 
    } 
}