Skip to main content
Home Forums General Silverlight Getting Started Question about class definition
10 replies. Latest Post by mchlSync on November 4, 2009.
(0)
Malone
Member
5 points
36 Posts
09-22-2009 10:25 AM |
Hi,
I have a weproject, a silverlight application and a silverlight class library. In the class library I have a class (name: variables), which had some properties and methods and which I like to use in the webproject and in the silverlight application.
Now I use the class "variables" in my webprojekt in an webservice (Webmethod) as a Parameter.
[WebMethod]
public byte[] CreatebyteArray(Variables _variables)
{
}
But when I create a new instance of the class "variables" in my silverlight application, where I create a proxy of the webservice, I only see the properties of the class and don't the methods.
Do you have any idea, why it is so?
Best Regards
mchlsync
Star
14606 points
2,730 Posts
09-22-2009 10:33 AM |
Hello,
Please try to use Silverlight-Enabled WCF service if you are not so familiar with Web Service and WCF service.
Let's say I have this method in Silverlight-Enabled WCF Service
[
I'm able to call this method after generating the proxy class.
client.CreatebyteArrayCompleted += (sender, e) => {
};
client.CreatebyteArrayAsync();
So, you may do the same thing. Hope it helps.
09-22-2009 12:53 PM |
unfortunately I can't test your code, but with your code I can use my class "variables" from my class library in both projects......webproject and silverlight application?
alok572
334 points
63 Posts
09-22-2009 1:33 PM |
You Paste the xaml.cs code so that we'll be able to help you.
And i would also suggest you to use WCF services rather than the asmx ones for better performance and also various advantages.
09-22-2009 3:39 PM |
alok572: Hi,You Paste the xaml.cs code so that we'll be able to help you.And i would also suggest you to use WCF services rather than the asmx ones for better performance and also various advantages.
I have a class in my class library:
public class Variables
private List<Variables> listvalues = new List<Variables>();
// Properties and Methods for e.g.
public void _AddVariable(string _fieldname, string _fieldstringvalue) { listvalues.Add(new Variables(_fieldname, _fieldstringvalue)); }
I use this class in my webproject in an webservice:
[WebMethod]public byte[] CreatebyteArray(Variables _variables){
// Here I go per foreach through "_variables", which contains a List
Now, I would like to use the class in my silverlight application:
public partial class viewPage : UserControl { // Proxys myProxy.VariablesServiceSoapClient variablesproxy; public viewPage () { // Required to initialize variables InitializeComponent(); this.Loaded += new RoutedEventHandler(vwUntwPruefungsergebnis_Loaded); } private void viewPage _Loaded(object sender, RoutedEventArgs e) { Variables listvariables = new Variables(); listvariables._AddVariable("Test", "Test"); // This Method is not available.....only the properties of the class!!! variablesproxy= new myProxy.VariablesServiceSoapClient ("VariablesServiceSoap", Globals.WebRootPath + @"Services/Variables/VariablesService.asmx"); variablesproxy.CreatebyteArrayCompleted += new EventHandler<CreatebyteArrayCompletedEventArgs>(variablesproxy_CreatebyteArrayCompleted); variablesproxy.CreatebyteArrayAsync(listvariables); }
private void variablesproxy_CreatebyteArrayCompleted(object sender, myProxy.CreatebyteArrayCompletedEventArgs e) { byte[] bytearray= e.Result; }
My "Variables" class has the reference to my "variablesproxy" and I can't see the methods of my class in intellisense. When the class "Variables" has the reference to my silverlight class library, then I can see the methods, but then I get an error, that the class has two references or it exist an ambivalent reference. I hope you know, what I mean!
09-23-2009 1:46 PM |
*push
I hope someone could help me, because I don't still find a solution!
K2P2
Participant
1028 points
337 Posts
09-23-2009 4:02 PM |
This might help:
http://forums.silverlight.net/forums/p/30046/96989.aspx#96989
If I understand you right you'll need three solutions:1) Your webservice solution - this refers to the dll produced by 3.A2) Your silverlight solution - this refers to the dll produced by 3.B3) A solution that that has two projects: A) project 1 with the file that holds your class and that compiles for the non-silverlight clr used by your webservice. B) project 2 with the file that holds your class and that compiles for the silverlight clr
09-23-2009 4:05 PM |
This is the more relevant post.
http://forums.silverlight.net/forums/p/22246/78539.aspx
mchlSync
09-24-2009 12:04 AM |
Sorry for late reply. I was busy yesterday and couldn't able to check the forum yesterday.
Malone:listvariables._AddVariable("Test", "Test"); // This Method is not available.....only the properties of the class!!!
Yes. It's because this method is not generated in proxy class (Reference.cs).
I think you will have to share the linked class betwen Silverlight class library and .NET class library and use the Channel Factory to invoke. Please wait.
09-24-2009 2:57 AM |
mchlsync:Sorry for late reply. I was busy yesterday and couldn't able to check the forum yesterday. Malone:listvariables._AddVariable("Test", "Test"); // This Method is not available.....only the properties of the class!!! Yes. It's because this method is not generated in proxy class (Reference.cs). I think you will have to share the linked class betwen Silverlight class library and .NET class library and use the Channel Factory to invoke. Please wait.
I can't really follow you. I hope you maybe have a code snippet for me!
And a big "Thank you" to all, who have answered me so far.
Best RegardsMalone
11-04-2009 10:12 AM |
Hey Malone,
Sorry about that. I was away from forum since I was too busy in new office. :(
Did you manage to solve your problem?