How to Access a Web Application Class in a Silverlight Application

I am new to silverlight. I have created a silverlight project. When a new silverlight project is created, it automatically creates a silverlight app and one web app. I added the class in both applications. Now I want to access the web application class method in the silverlight application class. Is it possible? I tried to add a web app link for silverlight, but VS won't resolve. Is there any other way to do it?

+2


a source to share


2 answers


What you need is called WCF. You can find a really simple tutorial here to guide you: How to Call WCF Methods from Silverlight Controls



Fundementally WCF allows a Silverlight client to make method calls to an instance of a class hosted on a website.

+2


a source


Yes, it is possible, but not in the usual way. A Silverlight node can only reference another Silverlight assembly (this is a VS2008 limitation, I don't know if it was changed in VS2010).

What you need to do is add the existing file to your Silverlight project, when the file browser dialog opens, you will navigate to the class file you want to reuse, but instead of just clicking the button, Add

click on the little down button on the button and select Add as link

- the file will now "exist "in both projects and can be used in both.



If you are going to do this repeatedly, you will want to move these common class files into a separate assembly, reference the project from your web application, and have an equivalent Silverlight class library that mirrors it (exchange files as references) and then reference the project. that's the Silverlight class library from your Silverlight application.

+1


a source







All Articles