Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. List over a web service

List over a web service

Scheduled Pinned Locked Moved C#
dotnetdata-structures
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yitzchok Dev
    wrote on last edited by
    #1

    [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 { }
        }
    
    M M 2 Replies Last reply
    0
    • Y Yitzchok Dev

      [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 { }
          }
      
      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      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. :)

      1 Reply Last reply
      0
      • Y Yitzchok Dev

        [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 { }
            }
        
        M Offline
        M Offline
        Mark Churchill
        wrote on last edited by
        #3

        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

        Y 1 Reply Last reply
        0
        • M Mark 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

          Y Offline
          Y Offline
          Yitzchok Dev
          wrote on last edited by
          #4

          Well I got it to work, it look like the auto-generated webservice created a class for my custom class

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups