1
Good staff,
I need to create a Web service WCF which receives a list of objects and inserts it into a database postgresql. To test created a client app Vb.net, but something is not going as expected.
So far I have implemented the following condition:
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)' cannot be converted to 'Mylistofclients'.
I think the problem has to do with list that has to be like 'Mylistofclients'.
Dim list As New List(Of APICS.MyListofClients)
however I can not understand how I should send the list this way
Any hint??