How to access web application class into silverlight application - silverlight

I am beginner in silverlight..I have created a silverlight project. When a new silverlight project is created it is automatically creating a silverlight application and one web application. I have added a class in both applications. Now I want to access a method of web application class into silverlight application class. Is it possible? I have tried to add web application reference to silverlight but VS is not allowing. Is there any another way to do??

What you need is called WCF. A really simple tutorial that should get you going is found here: How to call WCF methods from Silverlight controls
Fundementally WCF allows the silverlight client to make method calls on a class instance hosted on the web site.

Yes it is possible, but not in the normal way. A Silverlight assembly can only reference another Silverlight assembly (this is a limitation of VS2008, i don't know if it has been changed in VS2010).
What you need to do is add an existing file to your Silverlight project, when the file browse dialog opens you navigate to the class file you want to reuse, but instead of just clicking the Add button, click on the little down arrow on the button and choose Add as link - now the file will "exist" in both projects and can be used in both.
If you are going to do this repeatedly though, you will want to move those shared class files out into a separate assembly, do a project reference from your web app, and have the equivalent Silverlight class library mirroring it (sharing the files as links), and then project reference that Silverlight class library from your Silverlight app.

Related

How to use a Silverlight Solution

I have a Silverlight app made in Visual Studio 2010 and I want to put it on a website but I don't have the slightest clue how.
I've looked at all the msdn documentation and they all mention a .xap file that is the file you use on the website but there is no .xap and I can't find out how to compile my code into a .xap file.
Also, when I run the App and look at the source in the browser, it has my code compiled into the .xap file, but there is no .xap file!
So my question is simply how do you go about getting a Silverlight app on a website because I've been trying for hours and I can't figure it out.
A sample html or aspx page is included when you create the solution. This is the page that the browser navigates to when you hit F5. You can take that page as a basic example of how to embed a Silverlight app in a page. You should find it in the project folder.
Silverlight projects are commonly built into a XAP file when you hit "Build" in VS. This file lives in the bin/Release or bin/Debug folder and basically contains your whole application.
Steps to create a silverlight application Hosted in a web site,
Select Silverlight Application Template while adding new project in VS2010
When you click Ok, ensure that Host the Silverlight application in a new web site is Checked.(It will create a new ASP.Net web application to host the Silverlight)
If you haven't checked the Host the Silverlight application in a new web site option, you can add a new ASP.Net Web application project and then go to its properties and select Silverlight Applications option in left pane. Then Click Add, select your Silverlight Application to be hosted and click ok. You are done now.
But If haven't selected the Silverlight Application Template, then you might have created a Silverlight Class Library. It wont generate any xap file. It just gives a dll. So you need to recreate a project as mentioned above.
I believe that in Silverlight whenever you create a project, right at the beginning, it will ask you if you want to create a web app automatically. If you chose yes, something like YOUR_PROJECT_NAME.web will be created, go into that folder, you will find a folder called ClientBin.
The .xap file will be inside that folder.
HTH

Can DotNetOpenAuth be used within a Silverlight application

I have used DotNetOpenAuth previously in an ASP.net website and it works fine. But now I wanted to create a Silverlight app. Unfortunately I can't reference DotNetOpenAuth.dll, since this is not compiled against the Silverlight CLR. Is there a solution to use open authentication from Silverlight?
DotNetOpenAuth currently has this as an open issue for the group. Here's the link for the post and here is the link for the tracked item. There is this control a third party created, however it appears to me like it is not very secure so use it at your own risk. I only mention it because it could be a potential band-aid depending on the needs of your project.

Adding Models to the silverlight wcf ria services enabled application

I have started using the MVVm light2 framework for the wcf ria enabled silverlight 4.0 application.
I was able to add a folder named "Models" to ASP .Net application that hosts the silverlight application, I added a class to this folder, and i am able to set the properties and all for this in my silverlight application, but once i started to add more such classes into my Models folders, they aren't getting accessible anywhere in my silverlight application.
Also in my MainViewModel.cs the intellisense is not showing the newly added class/classes , i made sure the application is build before i accessed them in my silvelight application, also the namespaces are correct.
Am I missing to set a property or something?
Someone on my team faced a similar problem. As I recall it had something to do with the physical location on the .cs files, which may imply that the namespace had changed.

Generate Default Silverlight Web Project After Project Already Created

When you're creating a new Silverlight project, it asks you if you want to host the applicaiton in a new website and if you do so it generates a web project for you that's already setup and good to go. If you chose no when initially creating your Silverlight project is there any way to automatically generate this project?
Yes you can do it automatically still, and it works in both VS2010 and VS2008.
Right click on the project file of your web app in the solution explorer, and select Properties. Go to the Silverlight Applications tab, click Add.
From this dialog you can either select an existing Silverlight app from your solution, or create a new one. Don't forget to tick the Add a test page that references the control checkbox.

TestPage.aspx in silverlight

I am a beginner in silverlight. I want to know what is TestPage.aspx and TestPage.html in silverlight. Actually i have google it but din't get enough information. Can any one give me answer??
TestPage.aspx and TestPage.html are the pages which will host your Silverlight content. As you might know, Silverlight is just a project (not a web application) and needs a page that can host it.
These pages are created by default and help you to test your XAML content during your development, which you can later remove from your project.
TestPage.html is dynamically generated by the Silverlight application as part of the Debug process. If you take a look at the Debug tab for the application properties you will see an option to Dynamically generate a test page. If this is selected then you TestPage.html is created in the /Bin/Debug folder of your Silverlight application.
A better solution is to create a web application in the same solution as your Silverlight application then in the properties for the web application go to the Silverlight Applications tab and add your existing Silverlight app to the web project. Also make sure that the Silverlight checkbox is ticked in the Debuggers section of the Web tab of your web application.

Resources