0

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.

Ayaz
  • 2,111
  • 4
  • 13
  • 16
  • what is the issue with my code? If it works on my local machine, it should work on server too. – Ayaz Feb 03 '22 at 09:30
  • What error do you get when you invoke your service on the server? – Rahul Sharma Feb 03 '22 at 10:08
  • Incoming HTTP request to URI 'https://localhost:3424/api/stdataaccess/reports/123/summary' matched operation ''. Seems like it is not able to map to the method GetMTMReportBasedOnType and mapped to '' operation. – Ayaz Feb 03 '22 at 11:13
  • Maybe you try to give optional parameter default value null `UriTemplate = "GetMTMReportBasedOnType?runId={runId}&reportType={reportType}&param1={param1=null}&param2={param2=null}")]`.You can refer to other people's writing.https://stackoverflow.com/questions/5781342/wcf-and-optional-parameters and https://stackoverflow.com/questions/24769379/why-is-it-that-no-http-resource-was-found-that-matches-the-request-uri-here – Lan Huang Feb 04 '22 at 08:33

0 Answers0