Click here to Skip to main content
15,867,832 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

Struggling with OData V4 when calling a Function.
My Client sends to the service:
C#
http://wrk2198:80/services/ProjectUsedModels(modelNumber='10000')


The webapi service expects:
C#
http://wrk2198:80/services/ProjectUsedModels?modelNumber='10000'


I have tried so many things but I cannot figure out how this works.
How do I get client and service work together
Service is asp.net web api
Client is
"ProviderId": "Microsoft.OData.ConnectedService",
"Version": "0.4.0",

What I have tried:

In the webapiconfig I added the route
C#
config.Routes.MapHttpRoute(
                    name: "ActionAPI",
                    routeTemplate: "api/{controller}/{action}/{id})",
                    defaults: new { id = RouteParameter.Optional }
                );

The entity is defined in the config as
C#
modelBuilder.EntitySet<ProjectUsedModels_Result>("ProjectUsedModels");



The controller contains:
C#
[EnableQuery]
       public IEnumerable<ProjectUsedModels_Result> Get(string modelNumber = "")
       {
           try
           {
               var result = db.ProjectUsedModels(modelNumber);
               return result;
           }
           catch (Exception err)
           {
               Logging.Log.Instance.AddException(err);
               return new List<ProjectUsedModels_Result>();
           }
       }


Client Calling Code:
C#
public IEnumerable<ProjectUsedModels_Result> SearchProjectsThatUsedModel(string modelNumber)
        {
            var modelnumberParameter = new UriEntityOperationParameter("modelNumber", modelNumber);
            var uri = new Uri("ProjectUsedModels", UriKind.Relative);
            return Service.Execute<ProjectUsedModels_Result>(uri, "GET", false, modelnumberParameter);
        }
Posted
Updated 13-Mar-20 4:28am
v2
Comments
ZurdoDev 13-Mar-20 9:53am    
I'm confused. It sounds like you are saying that your code is not creating the url properly. If so, fix that. I'm not sure what the problem is.
Herman<T>.Instance 13-Mar-20 9:54am    
How?

OData V3 dis it correctly and V4 has new ways with Routing. I can't figure it out.
ZurdoDev 13-Mar-20 10:01am    
Are you calling the service? Or is your code the service?
Herman<T>.Instance 13-Mar-20 10:07am    
code is calling
ZurdoDev 13-Mar-20 10:09am    
So, where is the actual code that is calling out to the service?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900