I have a need to generate an XML code returned through a WebMethod () in the following format. Notice the content within the TAG <user_list>
, which must have a list (of) or an arraylist without grouping:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />
<soap:Body>
<ListAllUsersResult xmlns="http://teste/">
<return_code>0</return_code>
<return_msg>Usuarios obtidos com sucesso</return_msg>
<user_list>
<user_id>admin</user_id>
<user_full_name>Admin. do Sistema</user_full_name>
<user_id>12345</user_id>
<user_full_name>NOME DO FUNCIONARIO 1</user_full_name>
<user_id>678</user_id>
<user_full_name>NOME DO FUNCIONARIO 2</user_full_name>
</user_list>
</ListAllUsersResult>
</soap:Body>
</soap:Envelope>
However, when I generate XML, it comes out with a structure of my structure, placing additional TAGs. Note that the content <user_list>
for each group of records adds a <st_ListUser>
:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />
<soap:Body>
<ListAllUsersResult xmlns="http://teste/">
<return_code>0</return_code>
<return_msg>Usuarios obtidos com sucesso</return_msg>
<user_list>
<st_ListUsers>
<user_id>admin</user_id>
<user_full_name>Admin. do Sistema</user_full_name>
</st_ListUsers>
<st_ListUsers>
<user_id>12345</user_id>
<user_full_name>NOME DO FUNCIONARIO 1</user_full_name>
</st_ListUsers>
<st_ListUsers>
<user_id>678</user_id>
<user_full_name>NOME DO FUNCIONARIO 2</user_full_name>
</st_ListUsers>
</user_list>
</ListAllUsersResult>
</soap:Body>
</soap:Envelope>
The code I use to mount this XML is as below:
Public Structure Output_ListAllUsers
Public return_code As String
Public return_msg As String
Public user_list As List(Of st_ListUsers)
End Structure
Public Structure st_ListUsers
Public user_id As String
Public user_full_name As String
End Structure
<SoapDocumentMethod(ParameterStyle:=SoapParameterStyle.Bare), WebMethod()>
Public Function ListAllUsers(ByVal in_ListAllUsers As Input_ListAllUsers) As Output_ListAllUsers
Dim obj_Return As New Output_ListAllUsers
Dim obj_WS As New WS_functions(cc_Ambiente, _UID)
Try
Dim obj_WS_Result As WS_functions.st_ListAllUsers_Output = obj_WS.ListAllUsers()
Dim obj_Users As New List(Of st_ListUsers)
For Each dados As WS_functions.st_ListAllUsers_Users In obj_WS_Result._Users
obj_Users.Add(New st_ListUsers With {.user_id = dados.user_id, .user_full_name = dados.user_full_name})
Next
obj_Return.return_code = obj_WS_Result.Cod_Process
obj_Return.return_msg = obj_WS_Result.Desc_Process
obj_Return.user_list = obj_Users
Catch ex As Exception
obj_Return.return_code = 99
obj_Return.return_msg = ex.Message
Finally
ListAllUsers = obj_Return
End Try
End Function
Would anyone know how to guide me how do I generate XML the way I need it? I'm using VS2017 in VB and I have the need to keep in ASMX and I can not use WCF.
If you have the solution in C # it's also great!
Thank you!