0

我是 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);

请帮忙

谢谢

4

1 回答 1

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 Accounts以及如何使用 Windows 凭据访问网站

希望这有帮助。

于 2018-09-14T22:17:05.130 回答