我是Simple.Odata.client的新手。我在使用以下代码访问Odata服务时遇到问题。下面的代码返回null。但邮递员返回结果。
简单Odata客户端中没有UrlBase,但是有BAseUri
此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);
请帮助
谢谢
答案 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 Accounts和how to access website with Windows credential
希望获得帮助。