Web Api 2.2 OData V4 Function Routing

后端 未结 3 705
春和景丽
春和景丽 2021-01-01 23:19

I have a Web Api 2.2 project working with OData v4. The normal EntitySet configuration is working as desired with all http verbs. Where I am having a problem is trying to

相关标签:
3条回答
  • 2021-01-01 23:47

    Please change the element as below, which is the recommended way if there is dot in the request URL:

     <system.webServer>
            <modules runAllManagedModulesForAllRequests="true" />
     </system.webServer>
    

    and if

    http://something/odata/Products/ProductService.MostExpensive()
    

    is requested, I can get the data:

    {
    @odata.context: "http://localhost:14853/odata/$metadata#Edm.Double",
    value: 3
    }
    
    0 讨论(0)
  • 2021-01-01 23:50

    Then you may try adding the part not replacing them. Mine looks like below and it can work.

    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      <clear/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="/*"
          verb="*" type="System.Web.Handlers.TransferRequestHandler"
          preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    
    0 讨论(0)
  • 2021-01-01 23:58

    I know this question is not recent, but I found another answer that works for me. If you're willing to remove the namespace from the URL, you can use

    config.EnableUnqualifiedNameCall(true);
    

    Your URL would then look like this:

    http://something/odata/Products/MostExpensive
    

    See http://odata.github.io/WebApi/#06-01-custom-url-parsing. That's available in the Microsoft.AspNet.OData NuGet package.

    0 讨论(0)
提交回复
热议问题