Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

02 May 2009

Why you need Fiddler if you're publishing web sites

I'm publishing a new web site today (this is my new project that's using Silverlight, SQLite, LINQ via DbLinq and WCF). Well I tried to publish it on Monday but ran into a snag with the service I used to talk to the database. I thought it was a url problem, so I spent maybe an hour or two messing around with web.config and the service references in my Silverlight project. I've learned a couple of valuable lessons here.

Changing service references around can be a real hassle. There's two solutions to this. First, you can just have two references to the service in your Silverlight project, just changing the using statement at the top of your files to the one you want. However this might mean changing your code in more than one place, which will get old. Second, you can use a ServiceHostFactory (I read about this here):

public class MySiteHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
// Specify the exact URL of your web service
Uri webServiceAddress = new Uri(ConfigurationManager.AppSettings["ServiceUri_MySite"]);
ServiceHost webServiceHost = new ServiceHost(serviceType, webServiceAddress);
return webServiceHost;
}
}

And then add a key/value pair to your web.config. I did try this approach and it worked, but still didn't get to the root of my problem.

Get your policies straight. When you're deployed you'll probably want to lock down who can access your service. But in the meantime, open that policy right up. You'll need two files, clientaccesspolicy.xml and crossdomain.xml.

clientaccesspolicy.xml:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*" >
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>

And crossdomain.xml:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
NotFound can mean a lot of things. I kept getting a NotFound error out of my service. This was where I spent most of my time. Publishing the service? No prob. Opening up cross domain access? No prob. NotFound? What the heck does that mean. I could browse to the service. I could build a proxy using svcutil.exe. I was running my Silverlight app locally so I knew everything else was running right. So what the heck was going on? Well, a lot of messing around went by and still I didn't get anywhere until I did this:

Use Fiddler and add this to your web.config: <serviceDebug includeExceptionDetailInFaults="true" />. Using these two I found the issue in 10 minutes. Keep in mind that I was running the Silverlight app locally but I was pointing to the remote server. Turned out I was missing a dll (System.Data.SQLite). So I added it from my local dblinq directory. Still got the NotFound error. What?? Back to Fiddler. Go to the line that has the error (a 500 in my case) then Inspectors, TextView in the bottom pane. "The located assembly's manifest definition does not match the assembly reference": ah hah, wrong dll. Uploaded the correct one and away we went. All done.

Update: seetha asked what you need to do to get SQLite running on discountasp.net. The answer: not much. It's all about the trust level that your host let's you run .net apps under. Discountasp.net lets you run at Full Trust so there's no tweaking needed to get it going. Just make sure your app can find the .s3db file regardless of directory structure (I put mine in App_Data) and make sure you have the right version of your SQLite dll in your bin.

01 March 2009

Expression Blend 2

Been messing around with Expression Blend 2 tonight as I build my latest Silverlight project. Right now I have IE7, FF3, VS 2008 and Exp Blend 2 open. The XAML that I'm working on looks the same in IE and FF but doesn't match what VS 2008 and Expression Blend are showing me. I guess Blend is nice to have if you want to do animation but it's so crippled because there's no autocomplete. I find myself using VS 2008 for XAML editing because of that. Lacking autocomplete would be fine if all the language features were there in the properties pane. But for the life of me I can't find a MaxHeight property for an Image. Seems like that's pretty important for a designer to have. And since it's preview doesn't match what the browser is showing me, it's value is even more dubious.

Oh wait there it is, there's a little grayed out arrow at the bottom of that pane. You expand that and you get the advanced properties. Here's the image. Wow that thing is hard to see.


Still, lacking autocomplete is a deal breaker for me. Also, so far I see no way to change key bindings. Build solution in my VS is F6 but in EB it's Ctrl+Shift+B (while Run is F5). Lame.

21 December 2008

Yeah, but will it run Doom?

Read about this on Adam Kinney's blog. This is a great proof of concept for light gaming on the Silverlight platform. Looks damn good. Wish there were some higher res versions of the video.

http://www.innoveware.com/quakelight.html (scroll past the fold for videos)

There are some versions of Quake running in Flash, but they aren't ports they're just an interface over the top of the Quake code. The Innoveware Quake is a port from C++ to C#. It's still in progress, no real demo yet.

16 December 2008

Silverlight --> Windows

Just read the last post in Scott Gu's great intro to Silverlight. Great tutorial. But it was the last one that really shocked me: porting a Silverlight app to Windows. Seriously, very little work involved. I think if you knew what controls to avoid ahead of time you could make it almost seamless. Shawn Burke has a discussion here about why the transition isn't seamless now.

For my money, I'd start with Silverlight and port to Winforms. Basing that on the amount of jobs for asp.net devs vs. jobs for winforms devs. Expecting that trend to continue into the Silverlight world. There's also a big "why" for porting apps from Silverlight to winforms (WPF)? For line of business apps, if your connection to your db is down then having a WPF version of your app won't help you much. No network, no workie. And if your connection to your db is down so often that you really need to have a WPF version of your app, then you have a bigger fish to fry.

Now, if we're talking about a mobile app, then disconnected might matter, but we have many other issues to deal with as well, so it's a big conversation.

Also, got my "Nice Answer" badge on StackOverflow. Achievements for developers, whoop whoop.