Good people,
I need to create a WCF Web service that receives a list of objects and inserts it into a postgresql database. To test I've created a vb.net client app , but something is not going as expected.
So far I have the following status implemented:
IService.cs
public interface IService1
{
[OperationContract]
int InsertClients(MyListofClients clients);
}
[DataContract]
public class MyListofClients
{
[DataMember]
List<Client> Clients { get; set; }
}
[DataContract]
public class Client
{
[DataMember]
public string clientId { get; set; }
[DataMember]
public string ClientName { get; set; }
[DataMember]
public List<Client> Clients { get; set; }
}
}
Servic1.svc
public int InsertClients(MyListofClients clients)
{
int res, result;
using (NpgsqlConnection conn = new NpgsqlConnection(connStringFarm))
{
conn.Open();
List<MyListofClients> firstStringList = new List<MyListofClients>();
string cmdStr = String.Format("Insert Into table (x1,x2)" +
" VALUES(@x1,@x2)");
foreach (var item in firstStringList)
{
NpgsqlCommand cmd = new NpgsqlCommand(cmdStr, conn);
result = cmd.ExecuteNonQuery();
}
conn.Close();
return 0;
}
App Client
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim db_comm As New NpgsqlCommand
Dim Reader As NpgsqlDataReader
Dim query As String = "Select code1,name1 from clientes"
db_comm.CommandText = query
db_comm.Connection = conn
conn.open
Reader = db_comm.ExecuteReader
Dim list As New List(Of String)
While Reader.Read
list.Add(Reader.GetString("code1"))
list.Add(Reader.GetString("name1"))
End While
Dim API As APICS.Service1Client = New APICS.Service1Client()
API.InsertClientsAsync(list)
End Sub
ERROR Value of type 'List (Of String)' can not be converted to 'MyListofClients'.
I think the problem has to do with the list that must be of type ' MyListofClients '.
Dim list As New List(Of APICS.MyListofClients)
However I can not figure out how to send the list this way
Any tips ??