We have many services in our system. ( integrating with a mobile company)
So, (for example) we have :
Action1 in Controller1
Action2 in Controller1
...
Action4 in Controller4
Action5 in Controller4
...
Currently, the mobile company calls each action with a single request.
But recently they told us , "can we send you a list of Actions to invoke ? instead of running single action manually each time... ?"
So I tried reflection:
ServicesController
:
[HttpGet]
[AllowAnonymous]
public HttpResponseMessage AAA( )
{
Type type = typeof(UsersController);
var instance = Activator.CreateInstance(type);
MethodInfo method = type.GetMethod("Test2", BindingFlags.Instance | BindingFlags.Public);
var t= method.Invoke(instance, new object[] { "royi" });
return Request.CreateResponse(HttpStatusCode.OK, t);
}
And :
UseresController :
[HttpGet]
[AllowAnonymous]
public HttpResponseMessage Test2( string ggg)
{
return Request.CreateResponse(HttpStatusCode.OK, "hello"+ggg);
}
When I run via fiddler :
http://es.com/api/services/aaa
( GET)
It does work , but (obviously) the Request
on the other side is null :
Question
How can I make Test2
run as expected ? am I on the right direction of solving this ? or does webApi has built in mechanism for this sort of thing ?
Aucun commentaire:
Enregistrer un commentaire