调用IncrementKnowledgeArticleViewCount

时间:2016-04-05 00:32:43

标签: odata crm dynamics-crm-2016

我一直关注Microsoft's documentation调用他们的新Web API但是我在向它传递正确的参数时遇到了问题。

我认为问题在于Source参数是EntityType,但是我找不到任何关于如何通过GET传递它的文档在一个无约束的函数上。

有人能指出我正确的方向吗?

PS。必须在separately

中传递ViewDate参数

致电我正在制作:

  

http://hostname:5555/WPK/api/data/v8.0/IncrementKnowledgeArticleViewCount(Source=' 67322227-C8F7-E511-810C-005056B608D3',ViewDate = @ P1,位置= 1,计数= 1)@ P1 =' 2016-04- 04T17:00:00Z'

返回错误消息:

  

{" Message":"无法转换类型的对象   ' EdmValidCoreModelPrimitiveType'输入   ' Microsoft.OData.Edm.IEdmStructuredType'。"," ExceptionMessage":   "无法投射类型' EdmValidCoreModelPrimitiveType'至   键入' Microsoft.OData.Edm.IEdmStructuredType'。"," ExceptionType":   " System.InvalidCastException"," StackTrace":"在   Microsoft.Crm.Extensibility.OData.CrmODataPathHandler.Parse(IEdmModel   model,String serviceRoot,String odataPath)\ r \ n at   System.Web.OData.Routing.ODataPathRouteConstraint.Match(HttpRequestMessage   request,IHttpRoute route,String parameterName,IDictionary`2 values,   HttpRouteDirection routeDirection)\ r \ n at   System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage   请求,对象约束,字符串parameterName,   HttpRouteValueDictionary值,HttpRouteDirection   routeDirection)\ r \ n at   System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage   请求,HttpRouteValueDictionary值,HttpRouteDirection   routeDirection)\ r \ n at   System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot,   HttpRequestMessage请求)\ r \ n at   System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase   httpContext)"," ErrorCode":500}

1 个答案:

答案 0 :(得分:0)

source参数需要作为OData实体引用传递。像这样:

{"@odata.id":"knowledgearticles(da2500aa-2068-e611-8118-00155d011200)"}

以下是显示使用此方法的请求/响应:

GET < org uri >/api/data/v8.1/IncrementKnowledgeArticleViewCount(Source=@p1,ViewDate=@p2,Location=@p3,Count=@p4)?@p1=%7B%22@odata.id%22:%22knowledgearticles(da2500aa-2068-e611-8118-00155d011200)%22%7D&@p2=2016-08-22T04:26.59Z&@p3=1&@p4=10 HTTP/1.1
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    OData-MaxVersion: 4.0
    OData-Version: 4.0

    HTTP/1.1 200 OK
    Cache-Control: no-cache
    Pragma: no-cache
    Content-Type: application/json; odata.metadata=minimal
    OData-Version: 4.0

    {
       "@odata.context":"< org uri >/api/data/v8.1/$metadata#knowledgearticleviews/Microsoft.Dynamics.CRM.crmbaseentity/$entity",
       "@odata.type":"#Microsoft.Dynamics.CRM.knowledgearticleviews",
       "knowledgearticleviewsid":"e32500aa-2068-e611-8118-00155d011200"
    }

为了使这更容易阅读,这里是未编码的URL:

< org uri >/api/data/v8.1/IncrementKnowledgeArticleViewCount(Source=@p1,ViewDate=@p2,Location=@p3,Count=@p4)?@p1={"@odata.id":"knowledgearticles(da2500aa-2068-e611-8118-00155d011200)"}&@p2=2016-08-22T04:26.59Z&@p3=1&@p4=10

最近更新了文档以涵盖这种情况。见Use Web API functions > Pass reference to an entity to a function