0

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 method 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.

4

2 回答 2

0

所以,这就是我的阅读方式:

//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

如果您在 Visual Studio 中生成代理,则可以选择将数组转换为强类型列表对象(添加服务引用 -> 高级 -> 集合类型:System.Collections.Generic.List)。这样你就可以调用commandList.Add()。

另外,我不知道为什么从 getCommands() 返回的类型的名称是 List。

于 2010-09-17T00:50:29.483 回答
0

您不确定如何实际使用为您生成的 C# SOAP 客户端吗?

像这样的东西应该工作......

// 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
}

[编辑]正如 Nicholas 在他的回答中推断的那样,您的 SOAP 服务定义应该避免使用常见的类型名称,例如“List”,因为它会与System.Collections.Generic.List<T>.

于 2010-09-17T00:57:25.187 回答