簡體   English   中英

簡單的Odata Client使用身份驗證無法使用Odata

[英]Simple Odata Client to consume Odata with Authentication not working

我是Simple.Odata.client的新手。 我在使用以下代碼訪問Odata服務時遇到問題。 下面的代碼返回null。 但郵遞員返回結果。

  1. 疑似問題:如何使用'1000'&format = json傳遞網址字符串
  2. 下面的簡單odata客戶端設置是否正確?
  3. 簡單Odata客戶端中沒有UrlBase,但是有BAseUri

  4. 這個ODataClientSettings是否有效?

    var settings = new Simple.OData.Client.ODataClientSettings();

    settings.BaseUri =新的Uri(“ https://..../UoM ?$ filter = wer例如'1000'&format = json”);

    settings.Credentials =新的NetworkCredential(“ user1”,“ usrpwd”);
    var client = new ODataClient(settings);

請幫忙

謝謝

這對我有用

var credentials = new NetworkCredential(userName, password); //you can use the override with the domain too.
var settings = new ODataClientSettings(baseUrl, credentials) //baseUrl is a string.
        {
            IgnoreResourceNotFoundException = true,
            OnTrace = (x, y) => Debug.WriteLine(x, y),
            PayloadFormat = ODataPayloadFormat.Json, //here is where you specify the format
            IgnoreUnmappedProperties = true,
            RenewHttpConnection = true,
            TraceFilter = ODataTrace.All,
            PreferredUpdateMethod = ODataUpdateMethod.Merge
        };
var client = new ODataClient(settings);

您的baseUrl不應包含所有這些OData標記,而應包含服務的端點(例如https://myservice.mysite.com/api.svc) 然后,當您使用Simple.OData.Client時 ,資源URL將自動完成。

請查看OData標准以了解其工作原理,並查看Simple.OData.Client存儲庫的示例以更好地了解如何使用它。

為了更好地了解如何使用Windows身份驗證,您可以檢查Windows帳戶的身份驗證和授權以及如何使用Windows憑據訪問網站

希望對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM