Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am writing a microcontroller project which uses an ethernet controller (with a TCPIP Stack) to send HTTP Post requests.

The nature of the project means the number of parameters to be passed to the webmethod will vary (i.e. some of the Parameter names will vary as well as the total number of parameters to be sent).

I understand that a normal webmethod requires a fixed number of arguments to be passed to the webmethod.
i.e - The webmethod below requires TWO parameters to be passed.
C#
[WebMethod]
public string save(string Parameter1, string Parameter2)
{
//Do something
return "Hello World";
}


I am aware that one can use "overloaded" webmethods (Messagename) to allow for a different number of [pre-defined] parameters to be sent but this seems inflexible and would require a lot of duplication.

I discovered a snippet of code that allows for an XML string to be passed to a Webmethod as a single parameter (to be manually parsed).
C#
[WebMethod]
public string save(string saveXml)
{
//parse XML
return "Hello World";
}


My question is - Is the second method I mention acceptable practice and is there a JSON equivalent?

NOTE: I am already sending JSON for the OUTGOING response, I am looking for a JSON solution for INCOMING parameters.
Posted
Comments
Praveen Kumar Upadhyay 27-Nov-14 6:33am    
Not very clear, but what I got is you want to create a web services where it can be called by passing n number of parameters. This can be simply achieve with the below code.

[WebMethod]
public string save(string[] Parameters)
{
//Do something
return "Hello World";
}


while calling this web method you can pass n number of parameter in below format.

http://localhost:XXX/abc.asmx/save?parameters=1¶meters=2¶meters=3¶meters=4

1 solution

Yes, passing xml is a perfectly valid way of doing it. Or, the suggestion in the comment is fine too. You can also pass json as well. There are lots of samples online.
 
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