How implement a web method in web service which accepts too many arguments?
I'm writing a web servi开发者_JAVA技巧ce which one of it's web methods accept too many arguments around 20 items. how do I write my web method. should I get arguments one by one? something like this:
[WebMethod]
public string InsertWorkerVariableInfo(string UserName,string Password, string WorkerCode,int Allegiance,Int16 Religious,Int16 Marriage,Int16 Physical,Int16 Gallantry
,byte SponsershipQty,byte ChildQty,Int16 Military,string Tell,String CellPhone,int State,int City,int District,
string Address,string Postal,string Email,Int16 Religion,Int16 InsuranceType,string InsuranceCode,string Description,
string LocalIp,string[] Majors)
I'm going to disagree with Muhammad entirely. I had a method like this with a boatload of parameters and people (including me a few months later) found it EXTREMELY cumbersome to use. That's especially true if not all of them are required.
Instead we created a class to wrap the parameters and just passed that into the method. The class had properties for each parameter, and you only had to actually set the ones you were using (so the optional ones didn't have to be set at all).
I don't think there's a "right" answer on this because both work, but I found this method a lot more readable then a 20 parameter method call. YMMV. :)
精彩评论