OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
856 stars 474 forks source link

It can not find the correct overload function if the the function is exposed as a function import. #55

Closed LianwMS closed 8 years ago

LianwMS commented 9 years ago

If a function has 2 overload:

<Function Name="GetAllConventionCustomers" ReturnType="Collection(WebStack.QA.Test.OData.UnboundOperation.ConventionCustomer)" IsComposable="true" />
<Function Name="GetAllConventionCustomers" ReturnType="Collection(WebStack.QA.Test.OData.UnboundOperation.ConventionCustomer)" IsComposable="true">
    <Parameter Name="CustomerName" Type="Edm.String" FixedLength="false" Unicode="false" />
</Function>

and it is exposed as a function import:

<FunctionImport Name="GetAllConventionCustomers" Function="WebStack.QA.Test.OData.UnboundOperation.GetAllConventionCustomers" EntitySet="ConventionCustomers" IncludeInServiceDocument="true" />

Then requesting ~/$metadata will result in:

The path template 'GetAllConventionCustomersImport(CustomerName={customerName})' on the action 'GetAllConventionCustomers' in controller 'ConventionCustomers' is not a valid OData path template. The given OData path template 'GetAllConventionCustomersImport(CustomerName={customerName})' is invalid.","ExceptionType":"System.InvalidOperationException","StackTrace":"  
at System.Web.Http.OData.Routing.Conventions.AttributeRoutingConvention.GetODataPathTemplate(String prefix, String pathTemplate, HttpActionDescriptor action) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.OData\\OData\\Routing\\Conventions\\AttributeRoutingConvention.cs:line 272\r\n  
at System.Web.Http.OData.Routing.Conventions.AttributeRoutingConvention.<>c__DisplayClass11.<GetODataPathTemplates>b__e(ODataRouteAttribute route) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.OData\\OData\\Routing\\Conventions\\AttributeRoutingConvention.cs:line 243\r\n  
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n  
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\r\n  
at System.Web.Http.OData.Routing.Conventions.AttributeRoutingConvention.BuildAttributeMappings(IEnumerable`1 controllers) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.OData\\OData\\Routing\\Conventions\\AttributeRoutingConvention.cs:line 199\r\n  
at System.Web.Http.OData.Routing.Conventions.AttributeRoutingConvention.<>c__DisplayClass2.<>c__DisplayClass4.<.ctor>b__1() in c:\\WebApi\\aspnetwebstack\\src\\System.Web.OData\\OData\\Routing\\Conventions\\AttributeRoutingConvention.cs:line 59\r\n  
at System.Web.Http.OData.Routing.Conventions.AttributeRoutingConvention.get_AttributeMappings() in c:\\WebApi\\aspnetwebstack\\src\\System.Web.OData\\OData\\Routing\\Conventions\\AttributeRoutingConvention.cs:line 121\r\n  
at System.Web.Http.OData.Routing.Conventions.AttributeRoutingConvention.SelectController(ODataPath odataPath, HttpRequestMessage request) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.OData\\OData\\Routing\\Conventions\\AttributeRoutingConvention.cs:line 139\r\n  
at System.Web.Http.OData.Routing.ODataPathRouteConstraint.SelectControllerName(ODataPath path, HttpRequestMessage request) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.OData\\OData\\Routing\\ODataPathRouteConstraint.cs:line 181\r\n  
at System.Web.Http.OData.Routing.ODataPathRouteConstraint.Match(HttpRequestMessage request, IHttpRoute route, String parameterName, IDictionary`2 values, HttpRouteDirection routeDirection) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.OData\\OData\\Routing\\ODataPathRouteConstraint.cs:line 152\r\n  
at System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage request, Object constraint, String parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.Http\\Routing\\HttpRoute.cs:line 215\r\n  
at System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage request, HttpRouteValueDictionary values, HttpRouteDirection routeDirection) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.Http\\Routing\\HttpRoute.cs:line 236\r\n  
at System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.Http\\Routing\\HttpRoute.cs:line 143\r\n  
at System.Web.Http.HttpRouteCollection.GetRouteData(HttpRequestMessage request) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.Http\\HttpRouteCollection.cs:line 82\r\n  
at System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in c:\\WebApi\\aspnetwebstack\\src\\System.Web.Http\\Dispatcher\\HttpRoutingDispatcher.cs:line 67\r\n  
at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n  
at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext() in c:\\WebApi\\aspnetwebstack\\src\\System.Web.Http\\HttpServer.cs:line 223

The controller code snippet is

[HttpGet]
[Queryable]
[ODataRoute("GetAllConventionCustomersImport()")]
public IEnumerable<ConventionCustomer> GetAllConventionCustomers()
{
    return _customers;
}

[HttpGet]
[Queryable]
[ODataRoute("GetAllConventionCustomersImport(CustomerName={customerName})")]
public IEnumerable<ConventionCustomer> GetAllConventionCustomers([FromODataUri]String CustomerName)
{
    var customers = _customers.Where(c => c.Name.Contains(CustomerName));
    return customers;
}

It should choose the correct overload of the function.

Work Item Details

Original CodePlex Issue: Issue 1640 Status: Active Reason Closed: Unassigned Assigned to: xuzhg Reported on: Jan 21, 2014 at 12:48 PM Reported by: jinfutan Updated on: May 6, 2014 at 10:15 AM Updated by: xuzhg

LianwMS commented 9 years ago

On 2014-01-28 15:35:21 UTC, xuzhg commented:

It's a bug of OData Library. TFS 2012866 is created to track.

LianwMS commented 9 years ago

On 2014-02-14 11:41:51 UTC, jinfutan commented:

Reactive as it is depending on a ODL bug.

LianwMS commented 9 years ago

On 2014-05-04 11:19:33 UTC, xuzhg commented:

Depend on ODL related bug. So, postpone.

xuzhg commented 8 years ago

Close it because it had been resolved.