Optional Parameter in wcf restful api

158 Views Asked by At

I am using wcf restful api. This is the method I have exposed.

[OperationContract]
[WebGet(UriTemplate = "reports/{runId}/{reportType}/{param1=''}/{param2=''}",
        BodyStyle = WebMessageBodyStyle.Bare,
        ResponseFormat = WebMessageFormat.Json)]
string GetMTMReportBasedOnType(string runId, string reportType, string param1, string param2);

Mock implementation is as below.

public string GetMTMReportBasedOnType(string runId, string reportType, string param1, string param2)
{
   return "mock data";
}

When I try to invoke the method using the below uri from postman, it works perfectly fine on my local machine but when I deploy the service and try to access the same method, it doesn't work.

https://localhost:3424/api/stdataaccess/reports/123/summary

and If I just pass some dummy value as below, it works fine on local as well as on server.

https://localhost:3424/api/stdataaccess/reports/123/summary//

So the issue is with the default parameters. Not sure how to pass those default parameters. Since the code is working on my local machine and failing when I deploy it on the server.

0

There are 0 best solutions below