C# SOAP 复杂类型参数

发布于 2024-09-19 12:52:36 字数 280 浏览 6 评论 0原文

我正在 C# 中开发 SOAP 客户端,使用我在 PHP 中使用 NuSoap 公开的服务。从消费的角度来看,我的 Web 服务运行得很好,但我遇到的麻烦与传递复杂类型作为参数有关。

使用方法返回的复杂类型并不麻烦,但我似乎无法弄清楚如何在 C# 中实际操作我的复杂类型。

除非有人确实请求,否则我现在将省去冗长的 WSDL。但我尝试使用的复杂类型是另一个复杂类型的列表。我需要在 C# 应用程序中添加和删除列表中的项目,但我似乎不知道如何操作。

有人能指出我正确的方向吗?可根据要求提供更多信息。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

じее 2024-09-26 12:52:36

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

//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。通用列表)。这样你就可以调用commandList.Add()。

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

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.

北凤男飞 2024-09-26 12:52:36

您不确定如何实际使用为您生成的 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.Web.Services 冲突。 Collections.Generic.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>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文