0

So I have had an old api call with this signature

public dynamic Add(String organizationId, String locationId, String orderType, String massTypeId, double amount, DateTime from, DateTime to, double distance, Driving driving)

Now I have changed to like this

public dynamic Add(String organizationId, String locationId, String orderType, String massTypeId, double amount, DateTime from, DateTime to, double distance, bool driving)

The only difference is the type of last parameter. For now I have to have my old api call until my apps are deployed. But if try it locally I get this error

Multiple actions were found that match the request

In my data from client the last parameter looks like this

driving : true

I send data as JSON.

Does any body know why is it happening?

mohsinali1317
  • 4,255
  • 9
  • 46
  • 85
  • Did you change the signature or did you add a new method with just the slightly changed signature? – MilConDoin Apr 20 '17 at 13:08
  • I added the new one with slightly changed signature. The new one takes the last param as boolean. But I still have to have the older one until my apps are up and running. Or the older versions won't be able to talk to new api. – mohsinali1317 Apr 20 '17 at 13:11

2 Answers2

0

Multiple actions are found matching the request, It is better practice to use a a request object when you are migrating to new APIs. For using these two apis for now, you can specify a route name as decoration to be specific to your new route

[Route("MyNewApiAdd")]
public dynamic Add([FromBody]ReqObject req);

and define new

    public class ReqObject 
    {
    String organizationId{get;set;}
    String locationId{get;set;} 
    String orderType{get;set;}
    String massTypeId{get;set;}
    double amount{get;set;}
    DateTime from{get;set;}
    DateTime to{get;set;}
    double distance{get;set;}
    bool driving{get;set;}
    }
Jins Peter
  • 2,368
  • 1
  • 18
  • 37
0

Is this for Web API? If not, just ignore. If it is, I think what you are doing is not possible. What you did is overloading API methods which is not supported, instead you can have it like this.

See sample:

[ActionName("GetById")]
public Foo Get(int id) { //whatever }

[ActionName("GetByString")]
public Foo Get(string id) { //whatever }

[ActionName("GetByGUID")]
public Foo Get(Guid id)  { //whatever }


Thanks!
useAIble

Community
  • 1
  • 1
confused
  • 179
  • 12