Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have developed a WCF webservice and want to give optional query string parameters in the URI Template of WebGet method.
Saw in net that its not supported. Is there any work around for this. Kindly share if you have any ideas.

Thanks in advance
Posted

Yes, We can have work around for optional parameter.

See the below code,
if you call

http://<uri>/get - It will call the GetAllertion method
http://<uri>/get/12 - It will call the GetAPerson method with parameter alue 12

So these URL act as optional paramter
C#
//Get Operation
[OperationContract]
[WebGet(UriTemplate = "get" )]
List<person> GetAllPerson();
[OperationContract]
[WebGet(UriTemplate = "get/{id}")]
Person GetAPerson(string id);</person>


Let me know if it is helps to you.

Artha
 
Share this answer
 
Hi Artha,

The above mentioned method can be used but its not feasible if we have more number of parameters. Suppose say, there are 5 parameters then we need to write 25 functions which is not a good idea. Do you have any alternative for this criteria?

Thanks for the reply.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900