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. Web Development
  3. ASP.NET
  4. Web Service Complex Type returning

Web Service Complex Type returning

Scheduled Pinned Locked Moved ASP.NET
helpquestion
5 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.
  • D Offline
    D Offline
    Dirso
    wrote on last edited by
    #1

    Hi, I have this class:

    [Serializable]
    public class Item
    {
    public string ProdName { get; set; }
    public string Qty { get; set; }
    }

    [Serializable]
    public class Order
    {
    public DateTime Dt;
    public int CustomerId;
    public List Items;
    }

    It's implemented in a separated assembly and is used in a lot of projects (the class is bigger than it appears here) When I made a webService to return a List, I have two problems. 1) The WebReference I add in the client has a definition of Order that the compiler thinks it's not from the assembly they are defined into. I can't cast. I have to create a List and populate with the data returned from the WebMethod. Worst, It doesn't return a List<>, it returns an []. 2) The Item.Items is not a member of this new (mirror) type the webservice declares? Is there a way to fix it? At least the #2?

    Thanks, Dirso

    K K 2 Replies Last reply
    0
    • D Dirso

      Hi, I have this class:

      [Serializable]
      public class Item
      {
      public string ProdName { get; set; }
      public string Qty { get; set; }
      }

      [Serializable]
      public class Order
      {
      public DateTime Dt;
      public int CustomerId;
      public List Items;
      }

      It's implemented in a separated assembly and is used in a lot of projects (the class is bigger than it appears here) When I made a webService to return a List, I have two problems. 1) The WebReference I add in the client has a definition of Order that the compiler thinks it's not from the assembly they are defined into. I can't cast. I have to create a List and populate with the data returned from the WebMethod. Worst, It doesn't return a List<>, it returns an []. 2) The Item.Items is not a member of this new (mirror) type the webservice declares? Is there a way to fix it? At least the #2?

      Thanks, Dirso

      K Offline
      K Offline
      Karthik A
      wrote on last edited by
      #2

      1. As far as I know, XML doesn't have a list concept. It's just plain text. So a List is going to be returned as an array. However in the receiving end you could cast your T[] to List 2. You need XmlRoot and XmlInclude attributes in your WebMethod (for every user defined class - in your case for Order and Item). Refer these posts http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlincludeattribute.aspx[^] A forum discussion[^]

      Cheers, Karthik

      modified on Sunday, October 24, 2010 11:00 AM

      D 1 Reply Last reply
      0
      • D Dirso

        Hi, I have this class:

        [Serializable]
        public class Item
        {
        public string ProdName { get; set; }
        public string Qty { get; set; }
        }

        [Serializable]
        public class Order
        {
        public DateTime Dt;
        public int CustomerId;
        public List Items;
        }

        It's implemented in a separated assembly and is used in a lot of projects (the class is bigger than it appears here) When I made a webService to return a List, I have two problems. 1) The WebReference I add in the client has a definition of Order that the compiler thinks it's not from the assembly they are defined into. I can't cast. I have to create a List and populate with the data returned from the WebMethod. Worst, It doesn't return a List<>, it returns an []. 2) The Item.Items is not a member of this new (mirror) type the webservice declares? Is there a way to fix it? At least the #2?

        Thanks, Dirso

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #3

        Dirso wrote:

        1. The WebReference I add in the client has a definition of Order that the compiler thinks it's not from the assembly they are defined into. I can't cast. I have to create a List and populate with the data returned from the WebMethod. Worst, It doesn't return a List<>, it returns an [].

        This is correct (and good!) behaviour. The web service is supposed to be agnostic of the client (for example a Java client can consume a .Net web service and vice versa). This is the reason the list is returned as an array, as all languages have the concept of an array, but not a list. The same goes for the Order type not casting, the message passed between the client and server is just a "value bag" that looks like an object, you are supposed to populate proper objects from them when then response is recieved. When you generate the client, a new class type is created. The generated class will have a different namespace but normally the same name as the originating server type. This won't cast as it is a completely different type as far as the runtime is concerned, you have to write a convertor if you wish to include the original class. Web Services != Object Orientation.

        Sort of a cross between Lawrence of Arabia and Dilbert.[^]

        D 1 Reply Last reply
        0
        • K Karthik A

          1. As far as I know, XML doesn't have a list concept. It's just plain text. So a List is going to be returned as an array. However in the receiving end you could cast your T[] to List 2. You need XmlRoot and XmlInclude attributes in your WebMethod (for every user defined class - in your case for Order and Item). Refer these posts http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlincludeattribute.aspx[^] A forum discussion[^]

          Cheers, Karthik

          modified on Sunday, October 24, 2010 11:00 AM

          D Offline
          D Offline
          Dirso
          wrote on last edited by
          #4

          Hi! 1) I see, i think it would work, but the other problems keep comming 2) Didn't work for me. The Items are a IList I tried to XmlInclude Item, but it still doesn't seem to be exported

          Thanks, Dirso

          1 Reply Last reply
          0
          • K Keith Barrow

            Dirso wrote:

            1. The WebReference I add in the client has a definition of Order that the compiler thinks it's not from the assembly they are defined into. I can't cast. I have to create a List and populate with the data returned from the WebMethod. Worst, It doesn't return a List<>, it returns an [].

            This is correct (and good!) behaviour. The web service is supposed to be agnostic of the client (for example a Java client can consume a .Net web service and vice versa). This is the reason the list is returned as an array, as all languages have the concept of an array, but not a list. The same goes for the Order type not casting, the message passed between the client and server is just a "value bag" that looks like an object, you are supposed to populate proper objects from them when then response is recieved. When you generate the client, a new class type is created. The generated class will have a different namespace but normally the same name as the originating server type. This won't cast as it is a completely different type as far as the runtime is concerned, you have to write a convertor if you wish to include the original class. Web Services != Object Orientation.

            Sort of a cross between Lawrence of Arabia and Dilbert.[^]

            D Offline
            D Offline
            Dirso
            wrote on last edited by
            #5

            Yeah, you're right, it should be independent... it's just a lot of extra work (my objects are much more complex than what I showed).

            Thanks, Dirso

            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