I am working on sample application to get employment data from a server using a REST API.
[OperationContract]
[WebGet(UriTemplate = "/employ?id={empIDs}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
List GetEmpList(string empIDs);
To get the employ details I called it and it worked fine.
GetEmpList("1");
Above code takes only one ID, but I want multiple employ details. Then to get multiple employ I need to use URL <root>/employ?1d=1&id=41&id=45
But to solve this I called the GetEmpList()
API as below
GetEmpList("1&id=41&id=45");
But it give me an exception:
System.ServiceModel.EndpointNotFoundException
Message :
There was no endpoint listening at https://sample.com/rest/employ?id=221%26id%3d211%26id%3d%26id%3d1057%26id%3d%26id%3d445 that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
If I hard code URL as
[OperationContract]
[WebGet(UriTemplate = "/employ?id={empIDs}&id={empIDs2}&id={empIDs3}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
List GetEmpList(string empIDs, string empIDs2, string empIDs3);
then it works, but the problem is number of employ varies based on request.
My question is how to pass multiple parameter to an UriTemplate
?