List over a web service
-
[Serializable]
public class SpecialOccasionsItem
{
private int id;
private string mediafile;
public int ID
{
get{return id;}
set{ id = value;}
}
public string MediaFile
{
get {return mediafile;}
set{mediafile = value;}
}
public SpecialOccasionsItem()
{}
public SpecialOccasionsItem(int itemID, string mediaFile)
{
mediafile = mediaFile;
id = itemID;
}
}in the webservice there is the methed
[WebMethod]
public List<SpecialOccasionsItem> GetSpecialOccasionsCollection()
{
List<SpecialOccasionsItem> il = new List<SpecialOccasionsItem>();// here I add the stuff in to the list "not shown" return il; }
In the application that requests this web methed *I get a can't cast exception*
public List<SpecialOccasionsItem> GetSpecialOccasionsCollection()
{
try
{
List<SpecialOccasionsItem> il = new List<SpecialOccasionsItem>();
Array Gsoc = se.GetSpecialOccasionsCollection();for (int i = 0; i < Gsoc.Length; i++) { il.Add((SpecialOccasionsItem)Gsoc.GetValue(i)); } return il; } catch { } }
-
[Serializable]
public class SpecialOccasionsItem
{
private int id;
private string mediafile;
public int ID
{
get{return id;}
set{ id = value;}
}
public string MediaFile
{
get {return mediafile;}
set{mediafile = value;}
}
public SpecialOccasionsItem()
{}
public SpecialOccasionsItem(int itemID, string mediaFile)
{
mediafile = mediaFile;
id = itemID;
}
}in the webservice there is the methed
[WebMethod]
public List<SpecialOccasionsItem> GetSpecialOccasionsCollection()
{
List<SpecialOccasionsItem> il = new List<SpecialOccasionsItem>();// here I add the stuff in to the list "not shown" return il; }
In the application that requests this web methed *I get a can't cast exception*
public List<SpecialOccasionsItem> GetSpecialOccasionsCollection()
{
try
{
List<SpecialOccasionsItem> il = new List<SpecialOccasionsItem>();
Array Gsoc = se.GetSpecialOccasionsCollection();for (int i = 0; i < Gsoc.Length; i++) { il.Add((SpecialOccasionsItem)Gsoc.GetValue(i)); } return il; } catch { } }
AFAIK, it is not possible to pass the custom object by using this attribute "Serializable". In our project, we used to pass the custom object from web application to web service. (there is one debate about "passing custom object vs passing individual parameter") In order to do that, we have to put XML Seriablzable attribute (as same as the one generate for Proxy Class) in custom class instead of "
[Serializable]
"F16I wrote:
In the application that requests this web methed *I get a can't cast exception*
It is probably because of one auto-generated class in your proxy class.. Please check your proxy class of your webservice.. I believe that there are one class like that in it..
public class SpecialOccasionsItem { public int ID; public string MediaFile; .... }
If I'm right, please comment this class.. copy the attributes from this class. and paste them at the top of your class.. Let me know if you are not clear...Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
[Serializable]
public class SpecialOccasionsItem
{
private int id;
private string mediafile;
public int ID
{
get{return id;}
set{ id = value;}
}
public string MediaFile
{
get {return mediafile;}
set{mediafile = value;}
}
public SpecialOccasionsItem()
{}
public SpecialOccasionsItem(int itemID, string mediaFile)
{
mediafile = mediaFile;
id = itemID;
}
}in the webservice there is the methed
[WebMethod]
public List<SpecialOccasionsItem> GetSpecialOccasionsCollection()
{
List<SpecialOccasionsItem> il = new List<SpecialOccasionsItem>();// here I add the stuff in to the list "not shown" return il; }
In the application that requests this web methed *I get a can't cast exception*
public List<SpecialOccasionsItem> GetSpecialOccasionsCollection()
{
try
{
List<SpecialOccasionsItem> il = new List<SpecialOccasionsItem>();
Array Gsoc = se.GetSpecialOccasionsCollection();for (int i = 0; i < Gsoc.Length; i++) { il.Add((SpecialOccasionsItem)Gsoc.GetValue(i)); } return il; } catch { } }
Array Gsoc = se.GetSpecialOccasionsCollection(); Doesn't this web service call return a List? Why are you trying to assign it to an array? Where is the InvalidCastException being thrown? Is it this line?
Mark Churchill Director Dunn & Churchill
-
Array Gsoc = se.GetSpecialOccasionsCollection(); Doesn't this web service call return a List? Why are you trying to assign it to an array? Where is the InvalidCastException being thrown? Is it this line?
Mark Churchill Director Dunn & Churchill
Well I got it to work, it look like the auto-generated webservice created a class for my custom class