I need a way to configure my contract (method) to take a variable number of parameters. Because you should be able to pass 2 or 10 parameters to this end point.
Btw, the reason I return a Stream is because I serialize my data to XML manually (not important).
ServiceInterface:
[OperationContract]
Stream UpdateAgent(string token, string agentId, string newAgentName, string param1);
Service implementation:
[WebGet(UriTemplate = "/update_agent/{token}/{agentId}/{newAgentName}/{param1}")]
public Stream UpdateAgent(string token, string agentId, string newAgentName, string param1)
{
//do stuff here
}
This method is only available with this URI request:
/update_agent/<long number of chars and numbers>/123456/John Silver/<some ID of associated data>
But I want to be able to pass more params of strings, if I want to. I know that alters the end point of the contract – but is this possible?
To clarify, the following should trigger the same endpoint:
/update_agent/<long number of chars and numbers>/123456/John Silver/dom_81/pos_23
/update_agent/<long number of chars and numbers>/123456/John Silver/dom_120/dat_12/pos_10
/update_agent/<long number of chars and numbers>/123456/John Silver/con_76
Can anyone help me – because clearly I can’t make 10,000 methods taking care of each extra parameter…
I have solved my own problem, by doing the following:
Web.configfile:Web.config section:
configuration/system.webServer/This regex, I made, will transform an URL like this:
/service/update_agent/123a456b789c012d/agent_1/New Agent Name/d_1/e_2/f_3/g_4||
/Service/update_agent/123a456b789c012d/agent_1/New%20Agent%20Name?input=d_1/e_2/f_3/g_4Which means I can hit the same Service Endpoint no matter how much I append in the URL, and then just extract the query parameters with this code: