【问题标题】:Simple Odata Client to consume Odata with Authentication not working使用身份验证不工作的简单 Odata 客户端使用 Odata
【发布时间】:2018-09-15 17:17:25
【问题描述】:

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

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

  4. 此 ODataClientSettings 是否有效?

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

    settings.BaseUri = new Uri("https://..../UoM?$filter=wer eg '1000' &format=json");

    settings.Credentials = new NetworkCredential("user1", "usrpwd");
    var client = new ODataClient(settings);

请帮忙

谢谢

【问题讨论】:

  • 也许在它周围放一个WebUtility.UrlEncode();
  • 我不确定我做对了。我的网址无效。这里我如何使用你的建议。这是网址:strUrl = "https://..../HandlingUnitSet?$filter=Werk eq '1000'&$format=json" settings.BaseUri = new Uri(WebUtility.UrlEncode(strUrl));请告知如何正确处理。

标签: xamarin.forms simple.odata.client


【解决方案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 时,资源 url 将自动完成。

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

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

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多