Can't pass the <T> list to a web service?
I have the same classes on my server and on my web service. I have the following WebMethod:
[WebMethod]
public int CreateOrder(List<Purchase> p, string username)
{
o.Add(new Order(p,username));
return o.Count;
}
However, the following code runs on the server:
protected void CartRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
List<Purchase> l = ((List<Purchase>)Session["Cart"]);
if (e.CommandName == "Order")
{
localhost.ValidateService WS = new localhost.ValidateService();
WS.CreateOrder(l, Session["username"].ToString());
}
}
It gives the following error: Argument '1': cannot convert from 'System.Collections.Generic.List<Purchase>' to 'localhost.Purchase[]'.
How to transfer an object list<Purchase>to a web service?
When using such web services, it is List<T>converted to an array ( T[]) by default . Convert your list to an array by executing .ToArray()before passing it to a method.
Another option is to change the web service code generation settings to use lists instead of arrays.
, , , Purchase, , -, Purchase. , ( ). , - Automapper .
localohost.ValidateService is a proxy class with its own namespaces for classes: then "Order" is not the same as "localhost.Order"
if your calling web service is from a different method in the same web service class, try the following:
tihs.CreateOrder (l, Session ["username"]. ToString ());