简体   繁体   中英

.NET Web Service Design (1 to many parameters including images)

I have a requirement where I have to expose an IIS .Net Web Service that can accept 1 to many parameters for upload to SQL Server. Like these examples:

string, string, string, string, (string, string, image) repeat any combo of (...)
string, string, string, string, (string, null, null) repeat any combo of (...)
string, string, string, string, (string, null, image) repeat any combo of (...)
string, string, string, string, (string, string, null) repeat any combo of (...)

So the first 4 fields are constant
The next 3 fields repeat. (string, string, image) where the second string can be empty or the image can be empty or visaversa. ex:
string, string, string, string, (string, null, image), (string, string, null) ...etc

I need to write this in C#. Can be SOAP, Web API, WCF.
I don't know how to write the code to dynamically handle to 4th to x number of parms. I hope this makes sense! It's late!

Is this even possible? Currently I'm thinking no. If so could you provide sample C# code? Anyone out there having to do something like this. Maybe the design needs changed. Let me know your thoughts on this. Thanks

The only way I know to do this is with the params keyword, but you will need to put the Image after the first 3 strings. The method signature would look something like...

    public void DoSomething(string s1, string s2, string s3, string s4, Image I1, params string[] otherStrings) 
    {
         // do work here    
    }

For more info on the params keyword visit https://msdn.microsoft.com/en-us/library/w5zay9db.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM