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. WPF
  4. Error passing List as a parameter to web service

Error passing List as a parameter to web service

Scheduled Pinned Locked Moved WPF
helphtmldotnetwpfcom
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.
  • C Offline
    C Offline
    CBenac
    wrote on last edited by
    #1

    Error passing List as a parameter to web service This is my second post on the same subject, in an attempt to solve the same problem. I hope this time I've supplied enough and correct information. Given a basic service, it is possible to return a List from the web service using the GetList() method but the compiler gives an error when trying to send the list as a parameter in the SendList() method. Please check the code bellow. I've revised it. The error is on line # 88 (The compiler error description is at the end of the source code) Note: I've configured the ServiceReference to return System.Collections.Generic.List although I've tested all possible combinations. 1 namespace SilverlightApplication1.Web 2 { 3 [ServiceContract(Namespace = "")] 4 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 5 public class Service1 6 { 7 [OperationContract] 8 public List GetList() 9 { 10 // Add your operation implementation here 11 List myList = new List(); 12 myList.Add(new People() { name = "AAA", age = 42 }); 13 return myList; 14 } 15 [OperationContract] 16 public string SendList(List myList) 17 { 18 return myList[0].name; 19 } 20 } 21 22 public class People 23 { 24 public string name; 25 public int age; 26 } 27 } 28 29 30 "SilverlightApplication1.Home" 31 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 32 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 33 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 34 xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 35 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" 36 Title="Home" 37 Style="{StaticResource PageStyle}"> 38 39 46

    N M 2 Replies Last reply
    0
    • C CBenac

      Error passing List as a parameter to web service This is my second post on the same subject, in an attempt to solve the same problem. I hope this time I've supplied enough and correct information. Given a basic service, it is possible to return a List from the web service using the GetList() method but the compiler gives an error when trying to send the list as a parameter in the SendList() method. Please check the code bellow. I've revised it. The error is on line # 88 (The compiler error description is at the end of the source code) Note: I've configured the ServiceReference to return System.Collections.Generic.List although I've tested all possible combinations. 1 namespace SilverlightApplication1.Web 2 { 3 [ServiceContract(Namespace = "")] 4 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 5 public class Service1 6 { 7 [OperationContract] 8 public List GetList() 9 { 10 // Add your operation implementation here 11 List myList = new List(); 12 myList.Add(new People() { name = "AAA", age = 42 }); 13 return myList; 14 } 15 [OperationContract] 16 public string SendList(List myList) 17 { 18 return myList[0].name; 19 } 20 } 21 22 public class People 23 { 24 public string name; 25 public int age; 26 } 27 } 28 29 30 "SilverlightApplication1.Home" 31 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 32 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 33 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 34 xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 35 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" 36 Title="Home" 37 Style="{StaticResource PageStyle}"> 38 39 46

      N Offline
      N Offline
      Nigel Ferrissey
      wrote on last edited by
      #2

      I think the problem is that the People objects that you are trying to send are defined on the client side. The service is expecting the People objects that are defined on the service side - they are not the same thing. Try sending a list of ServiceReference1.People instead of SilverlightApplication1.People and see if you get the same error.

      1 Reply Last reply
      0
      • C CBenac

        Error passing List as a parameter to web service This is my second post on the same subject, in an attempt to solve the same problem. I hope this time I've supplied enough and correct information. Given a basic service, it is possible to return a List from the web service using the GetList() method but the compiler gives an error when trying to send the list as a parameter in the SendList() method. Please check the code bellow. I've revised it. The error is on line # 88 (The compiler error description is at the end of the source code) Note: I've configured the ServiceReference to return System.Collections.Generic.List although I've tested all possible combinations. 1 namespace SilverlightApplication1.Web 2 { 3 [ServiceContract(Namespace = "")] 4 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 5 public class Service1 6 { 7 [OperationContract] 8 public List GetList() 9 { 10 // Add your operation implementation here 11 List myList = new List(); 12 myList.Add(new People() { name = "AAA", age = 42 }); 13 return myList; 14 } 15 [OperationContract] 16 public string SendList(List myList) 17 { 18 return myList[0].name; 19 } 20 } 21 22 public class People 23 { 24 public string name; 25 public int age; 26 } 27 } 28 29 30 "SilverlightApplication1.Home" 31 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 32 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 33 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 34 xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" 35 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" 36 Title="Home" 37 Style="{StaticResource PageStyle}"> 38 39 46

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        In addition to Nigel's reply... Since you're using the automagic proxy generator, then you can look at the generated code on the client side: 1) Click on the client project in the Solution Explorer 2) Click the "Show All Files" button on the Solution Explorer's toolbar 3) Drill down the files tree from the service reference to find the    Reference.cs file - that will have the generated client-side classes In the generated code, there should be the People class you should be using. If it's not there, try using the DataContractAttribute on the server side:

        [DataContract]
        public class People
        {
        [DataMember]
        public string name;
        [DataMember]
        public int age;
        }

        (don't forget to update the service reference on the client to get new generated code!)

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        C 1 Reply Last reply
        0
        • M Mark Salsbery

          In addition to Nigel's reply... Since you're using the automagic proxy generator, then you can look at the generated code on the client side: 1) Click on the client project in the Solution Explorer 2) Click the "Show All Files" button on the Solution Explorer's toolbar 3) Drill down the files tree from the service reference to find the    Reference.cs file - that will have the generated client-side classes In the generated code, there should be the People class you should be using. If it's not there, try using the DataContractAttribute on the server side:

          [DataContract]
          public class People
          {
          [DataMember]
          public string name;
          [DataMember]
          public int age;
          }

          (don't forget to update the service reference on the client to get new generated code!)

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          C Offline
          C Offline
          CBenac
          wrote on last edited by
          #4

          Mark, It is there. Thanks for the extra info (Being able to look at the generated client-side class is really usefull) The problem is solved. Nigel's post was right. I apologize that I didn't mentioned it on the previous thread. But, there are 2 things I learned, besides these ones. 1. Starting with Net 3.51 it is not necessary to add the [Data Contract] anymore for know types. 2. It appears that SL 3 web services do not require to implement the interface

          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