.net 如何对odata端点执行搜索操作

.net 如何对odata端点执行搜索操作,.net,json,asp.net-web-api,odata,dynamics-crm-2016,.net,Json,Asp.net Web Api,Odata,Dynamics Crm 2016,CRM 2016公开了odata/web api,并且具有开箱即用的特性 我正在尝试执行以下请求: https://mycrmorg.com/api/data/v8.1/Search(AppointmentRequest=@request)?@request={"ServiceId":"0640dd7b-984f-e711-9425-00155dc0d345","AnchorOffset":1,"UserTimeZoneCode":1,"RecurrenceDuration":0,"Recurr

CRM 2016公开了odata/web api,并且具有开箱即用的特性

我正在尝试执行以下请求:

https://mycrmorg.com/api/data/v8.1/Search(AppointmentRequest=@request)?@request={"ServiceId":"0640dd7b-984f-e711-9425-00155dc0d345","AnchorOffset":1,"UserTimeZoneCode":1,"RecurrenceDuration":0,"RecurrenceTimeZoneCode":1,"RequiredResources":{"ResourceId":"2031105f-ec0d-e711-9417-00155d835de9"},"SearchWindowStart":"1754-01-01T00:00:00Z","SearchWindowEnd":"9999-12-30T23:59:59Z","SearchRecurrenceStart":null,"Duration":1,"Constraints":[],"Objectives":[],"NumberOfResults":1,"Sites":[]}
更漂亮的json版本:

{
   "ServiceId":"0640dd7b-984f-e711-9425-00155dc0d345",
   "AnchorOffset":1,
   "UserTimeZoneCode":1,
   "RecurrenceDuration":0,
   "RecurrenceTimeZoneCode":1,
   "RequiredResources":{
      "ResourceId":"2031105f-ec0d-e711-9417-00155d835de9"
   },
   "SearchWindowStart":"1754-01-01T00:00:00Z",
   "SearchWindowEnd":"9999-12-30T23:59:59Z",
   "SearchRecurrenceStart":null,
   "Duration":1,
   "Constraints":[

   ],
   "Objectives":[

   ],
   "NumberOfResults":1,
   "Sites":[

   ]
}
我得到的例外是:

    {
  "error":{
    "code":"","message":"An unexpected 'StartObject' node was found for property named 'RequiredResources' when reading from the JSON reader. A 'StartArray' node was expected.","innererror":{
      "message":"An unexpected 'StartObject' node was found for property named 'RequiredResources' when reading from the JSON reader. A 'StartArray' node was expected.","type":"Microsoft.OData.Core.ODataException","stacktrace":"   at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideComplexValue, String propertyName, Nullable`1 isDynamicProperty)\r\n   at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.<>c__DisplayClass14.<ReadComplexValue>b__12(PropertyParsingResult propertyParsingResult, String propertyName)\r\n   at Microsoft.OData.Core.JsonLight.ODataJsonLightDeserializer.ProcessProperty(DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Func`2 readPropertyAnnotationValue, Action`2 handleProperty)\r\n   at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadComplexValue(IEdmComplexTypeReference complexValueTypeReference, String payloadTypeName, SerializationTypeNameAnnotation serializationTypeNameAnnotation, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)\r\n   at Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadNonEntityValueImplementation(String payloadTypeName, IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean isTopLevelPropertyValue, Boolean insideComplexValue, String propertyName, Nullable`1 isDynamicProperty)\r\n   at Microsoft.OData.Core.UriParser.ODataUriConversionUtils.ConvertFromComplexOrCollectionValue(String value, IEdmModel model, IEdmTypeReference typeReference)\r\n   at Microsoft.OData.Core.UriParser.ODataUriUtils.ConvertFromUriLiteral(String value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBinder.ParseComplexOrCollectionAlias(QueryToken queryToken, IEdmTypeReference parameterType, IEdmModel model)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBinder.ParseAndBindParameterAliasValueExpression(BindingState bindingState, String aliasValueExpression, IEdmTypeReference parameterType)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBinder.BindParameterAlias(BindingState bindingState, FunctionParameterAliasToken aliasToken)\r\n   at Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken token)\r\n   at Microsoft.OData.Core.UriParser.Parsers.FunctionCallBinder.BindSegmentParameters(ODataUriParserConfiguration configuration, IEdmOperation functionOrOpertion, ICollection`1 segmentParameterTokens)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.TryBindingParametersAndMatchingOperationImport(String identifier, String parenthesisExpression, ODataUriParserConfiguration configuration, ICollection`1& boundParameters, IEdmOperationImport& matchingFunctionImport)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.TryCreateSegmentForOperationImport(String identifier, String parenthesisExpression)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.CreateFirstSegment(String segmentText)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.ParsePath(ICollection`1 segments)\r\n   at Microsoft.OData.Core.UriParser.Parsers.ODataPathFactory.BindPath(ICollection`1 segments, ODataUriParserConfiguration configuration)\r\n   at Microsoft.OData.Core.UriParser.ODataUriParser.Initialize()\r\n   at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath, ODataUriResolverSetttings resolverSettings, Boolean enableUriTemplateParsing)\r\n   at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)"
    }
  }
}
{
“错误”:{
“代码”:”“消息”:“从JSON读取器读取时,为名为“RequiredResources”的属性找到意外的“StartObject”节点。应为“StartArray”节点。”,“innererror”:{
“消息”:“在从JSON读取器读取时,为名为“RequiredResources”的属性找到意外的“StartObject”节点。应为“StartArray”节点。”,“键入”:“Microsoft.OData.Core.ODataException”,“stacktrace”:“位于Microsoft.OData.Core.JsonLight.ODataJSonLightProperty和DvalueDeserializer.ReadNontityValueImplementation”(字符串payloadTypeName、IEdmTypeReference expectedTypeReference、DuplicatePropertyNamesChecker DuplicatePropertyNamesChecker、CollectionWithoutExpectedTypeValidator collectionValidator、Boolean validateNullValue、Boolean IstoplePropertyValue、Boolean insideComplexValue、String propertyName、Nullable`1 isDynamicProperty)\r\n位于Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.c\u DisplayClass14.b\u 12(PropertyParsingreult PropertyParsingreult,String propertyName)\r\n位于Microsoft.OData.Core.JsonLight.odatajsonlight Deserializer.ProcessProperty(DuplicatePropertyNamesChecker DuplicatePropertyNamesChecker,Func`2 readPropertyAnnotationValue,Action`2 handleProperty)\r\n位于Microsoft.OData.Core.JsonLight.ODataJsonLightPropertyAndValueDeserializer.ReadComplexValue(IEdmComplexTypeReference complexValueTypeReference,String payloadTypeName,SerializationTypeNameAnnotation SerializationTypeNameAnnotation,DuplicatePropertyNamesChecker DuplicatePropertyNamesChecker)\r\n位于Microsoft.OData.Core.JsonLight.ODataJSonLightProperty和DValueDeserializer.ReadnEntityValueImplementation(字符串payloadTypeName、IEdmTypeReference expectedTypeReference、DuplicatePropertyNamesChecker DuplicatePropertyNamesChecker、CollectionWithoutExpectedTypeValidator collectionValidator、Boolean validateNullValue、Boolean IstoplePropertyValue、Boolean insideComplexValue、String propertyName、Nullable`1 isDynamicProperty)\r\n位于Microsoft.OData.Core.UriParser.ODataUriConversionUtils.ConvertFromComplexOrCollectionValue(字符串值,IEdmModel模型,IEdmTypeReference类型引用)\r\n位于Microsoft.OData.Core.UriParser.ODataUriUtils.ConvertFromUriLiteral(字符串值,ODataVersion版本,IEdmModel模型,IEdmTypeReference类型引用)\r\n位于Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBinder.ParseComplexOrCollectionAlias(QueryToken QueryToken,IEdmTypeReference parameterType,IEdmModel model)\r\n位于Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBindParameterAliasValue Expression(BindingState BindingState,String aliasValueExpression,IEdmTypeReference parameterType)\r\n位于Microsoft.OData.Core.UriParser.Parsers.ParameterAliasBinder.BindingParameterAlias(BindingState BindingState,FunctionParameterAliasToken)\r\n位于Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken令牌)\r\n位于Microsoft.OData.Core.UriParser.Parsers.FunctionCallBinder.BindSegmentParameters(ODataUrParserConfiguration配置、IEdmOperation FunctionorPertion、ICollection`1 segmentParameterTokens)\r\n位于Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.TryBindingParameters和MatchingOperationImport(位于Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.TryCreateSegmentForOperationImport(字符串标识符,字符串括号表达式)的字符串标识符、字符串括号表达式、ODataRupArserConfiguration配置、ICollection`1和boundParameters、IEdmOperationImport和matchingFunctionImport)\r\n\r\n位于Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.CreateFirstSegment(String segmentText)\r\n位于Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.Parsers\r\n位于Microsoft.OData.Core.UriParser.Parsers.ODataPathFactory.BindPath(ICollection`1段,ODataUriParserConfiguration配置)\r\n位于Microsoft.OData.Core.UriParser.ODataUriParser.Initialize()\r\n位于System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel模型、字符串serviceRoot、字符串odataPath、ODataUrireSolverSettings resolverSettings、布尔启用UriTemplateParsing)处\r\n位于System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel模型,字符串serviceRoot,字符串odataPath)\r\n位于Microsoft.Crm.Extensibility.OData.CrmODataPathHandler.Parse(IEdmModel模型,字符串serviceRoot,字符串odataPath)
}
}
}

我认为我对RequiredResources的编码可能有问题。我做错了什么?我如何将此请求发送给CRM?

我认为问题可能是您将
RequiredResources
用作对象而不是集合,请尝试将其更改为

"RequiredResources": [{
   "ResourceId":"2031105f-ec0d-e711-9417-00155d835de9"
}],
完全JSON

{
   "ServiceId":"0640dd7b-984f-e711-9425-00155dc0d345",
   "AnchorOffset":1,
   "UserTimeZoneCode":1,
   "RecurrenceDuration":0,
   "RecurrenceTimeZoneCode":1,
   "RequiredResources": [{
      "ResourceId":"2031105f-ec0d-e711-9417-00155d835de9"
   }],
   "SearchWindowStart":"1754-01-01T00:00:00Z",
   "SearchWindowEnd":"9999-12-30T23:59:59Z",
   "SearchRecurrenceStart":null,
   "Duration":1,
   "Constraints":[

   ],
   "Objectives":[

   ],
   "NumberOfResults":1,
   "Sites":[

   ]
}
所需资源 集合(RequiredResource ComplexType)

取自

错误消息实际上告诉您,解析器预期的是[而不是{symbol/token]