Skip to main content

Microsoft Silverlight

Answered Question Question about class definitionRSS Feed

(0)

Malone
Malone

Member

Member

5 points

36 Posts

Question about class definition

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

Malone

 

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP
Answered Question

Re: Question about class definition

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

[ServiceContract(Namespace = "")]

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

public class Service1 {

[OperationContract]

public Byte[] CreatebyteArray() {return null;

}

}

I'm able to call this method after generating the proxy class.

var client = new ServiceReference1.Service1Client();

client.CreatebyteArrayCompleted += (sender, e) => {

var list = e.Result;Console.WriteLine("");

};

client.CreatebyteArrayAsync();

So, you may do the same thing. Hope it helps.

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


Malone
Malone

Member

Member

5 points

36 Posts

Re: Question about class definition

Hi,

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?

Best Regards

Malone

alok572
alok572

Member

Member

334 points

63 Posts

Re: Question about class definition

 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.

Mark as answer if i have helped you.

Malone
Malone

Member

Member

5 points

36 Posts

Re: Question about class definition

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!

 

Best Regards

Malone

 

 

Malone
Malone

Member

Member

5 points

36 Posts

Re: Question about class definition

*push

 

I hope someone could help me, because I don't still find a solution! Sad

 

Best Regards

Malone

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Question about class definition

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.A
2)  Your silverlight solution - this refers to the dll produced by 3.B
3)   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

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Question about class definition

This is the more relevant post.

http://forums.silverlight.net/forums/p/22246/78539.aspx

mchlSync
mchlSync

Star

Star

14606 points

2,730 Posts

Silverlight MVP
Answered Question

Re: Question about class definition

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.

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


Malone
Malone

Member

Member

5 points

36 Posts

Re: Question about class definition

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! Smile

And a big "Thank you" to all, who have answered me so far.

 

Best Regards
Malone

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: Question about class definition

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?

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities