I have the below implementation of a REST apis:
using System.Web.Http;
public class DeploymentsController : ApiController
{
public HttpResponseMessage Post(
string subscriptionId,
string serviceName,
string deploymentSlot,
CreateDeploymentInput input)
{
. . .
}
public HttpResponseMessage Post(
string subscriptionId,
string serviceName,
string deploymentSlot,
UpdateDeploymentStatusInput input)
{
. . .
}
}
This is the routing:
config.Routes.MapHttpRoute(
name: "DeploymentSlots",
routeTemplate: "{subscriptionId}/services/hostedservices/{serviceName}/deploymentslots/{deploymentSlot}",
defaults: new
{
controller = "deployments",
});
config.Routes.MapHttpRoute(
name: "Deployments",
routeTemplate: "{subscriptionId}/services/hostedservices/{serviceName}/deployments/{deploymentName}",
defaults: new
{
controller = "deployments"
});
I wanted to add handling for a new "upgrade" action which will be like below:
POST /1d42d489-7a4f-4561-91a3-c2033c31f8c6/services/hostedservices/Mytalk123490193975/deployments/Mytalk12349019/?comp=upgrade HTTP/1.1
Content-Type: application/xml; charset=utf-8
x-ms-version: 2012-08-01
Host: localhost:33344
Content-Length: 340
Expect: 100-continue
Accept-Encoding: gzip, deflate
HTTP/1.1 100 Continue
<UpgradeDeployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="ht tp://www.w3.org/2001/XMLSchema-instance"><Mode>auto</Mode><PackageUrl>http://
talkserviceshared.blob.core.windows.net/mycontainer/PackageTXlCaXp0YWxrMTIzNDkwMTkzOTc1
So I added a handler in the ApiController:
public HttpResponseMessage Post(
string subscriptionId,
string serviceName,
string deploymentSlot,
UpgradeDeploymentInput input)
{
. . .
}
but when I invoke it using the client, it complained "Multiple actions were found that match the request "
public HttpResponseMessage Post(
string subscriptionId,
string serviceName,
string deploymentSlot,
UpdateDeploymentStatusInput input)
and
public HttpResponseMessage Post(
string subscriptionId,
string serviceName,
string deploymentSlot,
UpdateDeploymentStatusInput input)
Then I tried combining the methods into one:
public HttpResponseMessage Post(
string subscriptionId,
string serviceName,
string deploymentSlot,
object input)
{
}
and wrote code that checks the runtime type and takes different actions. But this time the invocation fails with System.InvalidOperationException
Please help before I shoot myself. I don't have time to learn this stuff from scratch, I'm time crunched.