C# SOAP Complex Type Argument
I am working on a SOAP Client in C#, consuming a service I've exposed in PHP using NuSoap. My web service is working great from a consumption standpoint, but the trouble I'm running into has to do with passing a complex type as an argument.
Working with a complex type returned by a me开发者_JAVA技巧thod is no trouble, but I can't seem to figure out how to actually manipulate my complex type in C#.
Unless someone actually requests it, I'll spare the lengthy WSDL for now. But the complex type I'm trying to work with is a list of another complex type. What I need to do in my C# app is add and remove items from the list, but I can't seem to figure out how.
Could anyone point me in the right direction? More information can be provided upon request.
So, this is how I read this:
//instantiate proxy
var commandList = getCommands(authToken);
//build an array of new commands
var commands = new [] { new Command { id = "SomeID", command = "SomeCommand" } /*, etc.*/ } };
//assign commands to your list
commandList.Commands = commands;
//do something with the commandList object
If you are generating the proxy in Visual Studio, there is an option to turn the arrays into strongly typed List objects (Add Service Reference -> Advanced -> Collection type: System.Collections.Generic.List). This way you can just call commandList.Add().
Also, I don't know why the name of the type that is returned from getCommands() is List.
Are you unsure how to actually use the C# SOAP client which has been generated for you?
Something like this should work...
// Edit an existing file command.
using (var client = new mysiteServicePortTypeClient()) {
string auth = client.doAuth("user", "pass");
List l = client.getCommands(auth); // get all of the Command[] arrays
Command file = l.files[0]; // edit the first Command in the "files" array (will crash if Length == 0, of course
file.command = "new command"; // since the Command is in the array, this property change will stick
client.submitResults(auth, l); // send back the same arrays we received, with one altered Command instance
}
[Edit] As Nicholas infers in his answer, your SOAP service definition should avoid using common type names such as "List" because it will conflict with System.Collections.Generic.List<T>
.
精彩评论