1

我一直在关注微软关于调用他们新的 Web API 的文档,但是我在传递正确的参数时遇到了问题。

我认为问题出在Source应该是 a 的参数上EntityType,但是我找不到任何有关如何通过GET未绑定函数上的 a 传递它的文档。

谁能指出我正确的方向?

附言。参数ViewDate必须单独传入

我正在拨打的电话:

http://hostname:5555/WPK/api/data/v8.0/IncrementKnowledgeArticleViewCount(Source= '67322227-C8F7-E511-810C-005056B608D3',ViewDate=@p1,Location=1,Count=1)?@p1 ='2016-04-04T17:00:00Z'

返回错误信息:

{“消息”:“无法将“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 在 System.Web.Http.Routing.HttpRoute。ProcessConstraint(HttpRequestMessage 请求,对象约束,字符串参数名称,HttpRouteValueDictionary 值,HttpRouteDirection routeDirection)\r\n 在 System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage 请求,HttpRouteValueDictionary 值,HttpRouteDirection routeDirection)\r\n 在系统。 Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request)\r\n at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)", "ErrorCode": 500 }HttpRouteDirection routeDirection)\r\n 在 System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage 请求)\r\n 在 System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)", “错误代码”:500 }HttpRouteDirection routeDirection)\r\n 在 System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage 请求)\r\n 在 System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)", “错误代码”:500 }

4

1 回答 1

0

源参数需要作为 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

最近更新了文档以涵盖这种情况。请参阅使用 Web API 函数 > 将对实体的引用传递给函数

于 2016-08-22T04:47:05.847 回答