可以使用Simple Odata Client来使用Windows authentifaction请求我的Odata服务(由Asp.Net MVC托管)吗?
简单的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 :(得分: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
})
{
}
}