|
|
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 ="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 <grid x:name="LayoutRoot" >
40="" <scrollviewer="" style="{StaticResource PageScrollViewerStyle}" >
41=""
42="" <stackpanel="" >
43=""
44="" <textblock=""
45="" text="Home">
46 <textblock x:name="ContentText" style="{StaticResource ContentTextStyle}"
47="" text="Home page content">
48
49
50
51
52
53
54
55
56
57
58
59
60 namespace SilverlightApplication1
61 {
62 public partial class Home : Page
63 {
64 public Home()
65 {
66 InitializeComponent();
67 }
68
69 private void btnGetList_Click(object sender, RoutedEventArgs e)
70 {
71 ServiceReference1.Service1Client proxy = new SilverlightApplication1.ServiceReference1.Service1Client();
72 proxy.GetListCompleted +=new EventHandler<silverlightapplication1.servicereference1.getlistcompletedeventargs>(proxy_GetListCompleted);
73 proxy.GetListAsync();
74 }
75 // THIS WORKS
76 void proxy_GetListCompleted(object sender, SilverlightApplication1.ServiceReference1.GetListCompletedEventArgs e)
77 {
78 MessageBox.Show(e.Result[0].name + " " + e.Result[0].age.ToString());
79 }
80
81 private void btnSendList_Click(object sender, RoutedEventArgs e)
82 {
83 List<people> myList = new List<people>();
84 myList.Add(new People() { name = "AAA", age = 42 });
85
86 ServiceReference1.Service1Client proxy2 = new SilverlightApplication1.ServiceReference1.Service1Client();
87 proxy2.SendListCompleted += new EventHandler(proxy2_SendListCompleted);
88 proxy2.SendListAsync(myList); // COMPILE ERROR SEE DESCRIPTION BELLOW
89 }
90
91 void proxy2_SendListCompleted(object sender, SilverlightApplication1.ServiceReference1.SendListCompletedEventArgs e)
92 {
93 throw new NotImplementedException();
94 }
95 }
96
97 public class People
98 {
99 public string name;
100 public int age;
101 }
102 }
103
Error 2 Argument '1': cannot convert from 'System.Collections.Generic.List<silverlightapplication1.people>' to 'System.Collections.Generic.List<silverlightapplication1.servicereference1.people>' e:\SilverlightApplication1\Views\Home.xaml.cs 42 34 SilverlightApplication1
Error 1 The best overloaded method match for 'SilverlightApplication1.ServiceReference1.Service1Client.SendListAsync(System.Collections.Generic.List<silverlightapplication1.servicereference1.people>)' has some invalid arguments e:\SilverlightApplication1\Views\Home.xaml.cs 42 13 SilverlightApplication1
|
|
|
|
|
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.
|
|
|
|
|
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++
|
|
|
|
|
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
|
|
|
|
|
Hello To All,
I have developed a WPF Browser Application that captures webcam and broadcasts to to the persons in the list-box.
My problem is i m able to broadcast my webcam but when i see other webcam it shows me mixed streaming of both webcam 's .
One more problem is when two webcam get connected it gets very slow.
public void ShowVideo(Stream stream)
{
try
{
using (System.Drawing.Image objimage = System.Drawing.Image.FromStream(stream,true))
{
Bitmap objbitmap = new Bitmap(objimage);
MemoryStream str= SetImageSize(objbitmap);
Bitmap bitnew = new Bitmap(str);
IntPtr hBitmap = bitnew.GetHbitmap();
BitmapSource bmpSrc = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero,
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
DeleteObject(hBitmap);
imageOnlineUser.Source = bmpSrc;
if (this.ConnectDisconnect == false)
{
btnVideoShare.IsEnabled = false;
}
stream.Flush();
stream.Dispose();
GC.Collect();
}
}
catch (Exception ex) { }
}
I m using above method to show my webcam.
Please Help Me.
With Best Regards
Hardeep Singh Bhullar
Hardeep Singh Bhullar
|
|
|
|
|
how can i create a window with may user control ? and how do i connect them with each other?
modified on Monday, October 19, 2009 7:36 AM
|
|
|
|
|
nerra wrote: How can i create a window that has many user control ? and how do i connect this
You start by learning the language that you wish to use, usually by buying a book and studying hard. When you have a problem with your program you can post a question here and ask for help.
|
|
|
|
|
I appreciate your answer but there is no available book here in my country. If i buy it online i can't afford it. Thank you for your answer
modified on Monday, October 19, 2009 6:16 AM
|
|
|
|
|
nerra wrote: I appreciate your answer but there is no available book here in my country. If i buy it online i can't afford it. Thank you for your answer
According to your homepage your country is USA where you can buy books on every subject you may need. Secondly if you cannot afford to buy a book then I suggest you try some of the tutorials on the internet as you obviously have access to that. There are hundreds of articles here on The Code Project, and other sites, to get you started.
Your question is far too general for anyone here to give you a simple answer, you must do your own work first.
|
|
|
|
|
oh I'm sorry i did not notice that my country was in USA i will change it immediately sorry for the confusion sorry .... I may have an internet it is not good for playing video though .... again i an deeply apologize for the confusion of the country post homepage... I am not looking for a debate ...I appreciate that you have concern about my study habit... if you think this is just a shallow question then i will delete this thread after i figure how i can delete it... again i thank you and i apologize for the confusion
|
|
|
|
|
nerra wrote: if you think this is just a shallow question
No, your question is fine. I was just trying to explain that what you are asking for cannot be answered in a forum like this, as it would take too long. If you read some of the introduction articles on the subject of your choice they will show you how to do the things you want to learn. Then when you find something that you have difficulty understanding, or that does not seem to work, you can post a question and people will try to help.
|
|
|
|
|
I understand thank you i'll just try searching for more resource
|
|
|
|
|
Assuming you want to use WPF since you asked in this forum...
The entire SDK is available free online, and it also is included
with Visual Studio:
Windows Presentation Foundation[^]
I always recommend reading the entire SDK TWICE, maybe
trying out some code the second time through. It's amazing how few
questions one will have if one knows the fundamentals...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes, i do want to use wpf it's for my thesis. Thank you for your advice .
|
|
|
|
|
nerra wrote: yes, i do want to use wpf it's for my thesis.
Maybe your first question should have been : How can I find some resource to learn WPF?
|
|
|
|
|
I did do some research .....I did try some sample but this is the only topic that i had some difficulty ... But I would be happy if you can post some Thank you
|
|
|
|
|
nerra wrote: But I would be happy if you can post some
This is far too wide a subject to post an answer here. Take a look at some of the WPF articles here on Code Project for further information.
|
|
|
|
|
nerra wrote: how can i create a window with may user control ?
Do you mean 'many' ? You just add them, one at a time. It's no different, no matter how many there are
nerra wrote: and how do i connect them with each other?
To communicate between classes, use delegates.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
What I mean in 'many' is that ... I was going to create a some what like start scree/welcome screen that connected to other screen in a single window
.... thank you
|
|
|
|
|
i want to upload a file using a batch file and check the upload staus from asp.net code. please suggest me the proper command line argument in batch file.
mannu
|
|
|
|
|
What does this have to do with WPF, WCF or WF?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
First of all, what you want is not possible. Second, if it was possible, it's plain that you're too dumb to do it. This is the WPF/WCF forum.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I don't think he liked our answers mate.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
How to handle WPF datagrid row double click event? I tried with PreviewMouseClick. But it is getting throwed when clicked on header also.
Private Sub dbGrid_PreviewMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles dbGrid.PreviewMouseDoubleClick
If Not dbGrid.SelectedItem Is Nothing Then
MsgBox(DirectCast(DirectCast(DirectCast(dbGrid.SelectedItem, System.Object), System.Data.DataRowView).Row, System.Data.DataRow).ItemArray(0).ToString)
End If
e.Handled = True
End Sub
How to handle it only for datagrid row?
|
|
|
|