0

I want to access a remote SQL database for my Silverlight client. I know that there are various ways to do this (Entity Framework model, Linq to SQL), but all of those rely on something in the web project (or, at least, all of the tutorials I've read do). What's unusual for me is that there is no web project, which of course prevents me from using various assemblies.

The only thing I do have which might be useful is a WCF service running on IIS, which will have less limitations (and I can add that as a service reference in my SL project). But I'm not even sure if this is a feasible option for this problem.

Any solutions or suggestions would be great.

Thanks.

Edit: Thanks for the suggestions guys, but here's a little more: I am making an individual XAP that is loaded into something else (someone else's project is importing and loading the XAP files), so I don't have access to the web component. The loader itself will be hosted within a website (at least, I assume it will be).

I already have a WCF service set up which is currently hosted in IIS, so I can potentially create something here. How? Well, it seems I can generate the ORM classes using SQLMetal.exe, and then import that code into the WCF service. This will allow the service to make calls to the remote database and have that data returned in C# classes. The perhaps I'll make those data classes as ServiceContracts and pass the data that way. What's the problem here? Well, to be honest, I'm not really sure how it would work. I mean, I call the WCF Service from the SL application, which does its thing. It then must contact the SL application (I have no idea how to do that part) and send along a load of data. It would be great if someone had has experience of this and would offer some suggestions. I know it's not really how you're supposed to do it, but I've drawn the short straw so I'm stuck with it.

7
  • 1
    why write in silverlight if not for web. Wouldn't wpf be easier? Commented Nov 30, 2011 at 15:04
  • how would you run the SL app if not in the browser reneding a web site? Commented Nov 30, 2011 at 15:07
  • Is there a restriction on using/adding a web application/project? Are you hosting your Silverlight across a Network? Please explain your target environment. Commented Nov 30, 2011 at 15:10
  • @DavidePiras: that is actually quite easily possible. You can just start the hosting HTML file locally or even from a network share. I understand this is not the best practise, but it is possible :-) Commented Nov 30, 2011 at 15:11
  • @Rody, are you sure about that? Every time I've tried to load a SL app from file:\\ it just goes to the forever spinning Silverlight logo. Commented Nov 30, 2011 at 15:15

3 Answers 3

2

Ok, so if I understand it correctly, you use a Silverlight application (XAP) which is started locally from a network share or something? Because why would you not have a web project when using Silverlight? (is there no server available to host it?)

But ok, when that is the case, you can access a WCF service from Silverlight. However it has some limititations. For instance you can only use asynchronous calls to the service, and you can only use WCF basichttpbinding as binding for the WCF service.

See: http://msdn.microsoft.com/en-us/library/cc197959%28v=vs.95%29.aspx

Sign up to request clarification or add additional context in comments.

3 Comments

I was not aware that Silverlight could access a WCF service that is not hosted on the same location as the Silverlight originates.
That is possible using cross domain policy files. By default, Silverlight supports calls to Web services on the same domain or site of origin. Same domain means that calls must use the same sub domain, protocol, and port. See this link: msdn.microsoft.com/en-us/library/cc197955%28v=vs.95%29.aspx
Actually, you can use a Net.TCP binding as well (which is much faster). And a HttpDuplexBinding (if you need duplex and are stuck with HTTP).
1

First, I would recommend you use WPF instead of Silverlight for this project. If you're not using this as a web client, then WPF is a million times easier / better.

But if that's not a possibility:

You can write a self-hosted WCF service and run it somewhere accessible. Self-hosted will allow for WCF connections to connect without the IIS necessary. In your self-hosted program you need:

  1. Front end WCF defined
  2. Back end SQL database
  3. Depending on how smart this client needs to be, a BusinessLogic layer to transform the data from WCF to SQL.

Comments

1

Silverlight is sandboxed, so it can only access its own Web application. Therefore, your best bet is to include a WCF or ASMX web service in your web application that handles the DB access.

If you don't want to run a sandboxed UI on a Web application, you cannot use Silverlight but should use WebForms or Windows Presentation Foundation (WPF) instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.