簡體   English   中英

C#SOAP復雜類型參數

[英]C# SOAP Complex Type Argument

我正在使用C#開發SOAP客戶端,使用了使用NuSoap在PHP中公開的服務。 從消耗的角度來看,我的Web服務運行良好,但是我遇到的麻煩與傳遞復雜類型作為參數有關。

使用方法返回的復雜類型沒有問題,但是我似乎無法弄清楚如何在C#中實際操作我的復雜類型。

除非有人真正要求,否則我將暫時保留冗長的WSDL。 但是我要使用的復雜類型是另一種復雜類型的列表。 我需要在C#應用程序中執行的操作是從列表中添加和刪除項目,但是我似乎無法弄清楚該如何做。

有人能指出我正確的方向嗎? 可根據要求提供更多信息。

因此,這就是我的閱讀方式:

//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中生成代理,則可以使用一個選項將陣列變成強類型的List對象(添加服務參考->高級->集合類型:System.Collections.Generic.List)。 這樣,您可以只調用commandList.Add()。

另外,我也不知道為什么從getCommands()返回的類型的名稱是List。

您不確定如何實際使用為您生成的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>沖突。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM