简单的Odata Client使用身份验证无法使用Odata

时间:2018-06-27 07:32:30

标签: xamarin.forms simple.odata.client

我是Simple.Odata.client的新手。我在使用以下代码访问Odata服务时遇到问题。下面的代码返回null。但邮递员返回结果。

  1. 怀疑的问题:如何使用'1000'&format = json
  2. 传递url字符串
  3. 以下简单的odata客户端设置是否正确?
  4. 简单Odata客户端中没有UrlBase,但是有BAseUri

  5. 此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);

请帮助

谢谢

1 个答案:

答案 0 :(得分:1)

这对我有用

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时,资源网址将自动完成。

请查看OData标准以了解其工作原理,并查看Simple.OData.Client存储库的示例以更好地了解如何使用它。

要更好地了解如何使用Windows身份验证,可以检查Authentication and Authorization with Windows Accountshow to access website with Windows credential

希望获得帮助。