Nerdy tidbits from my life as a software engineer

Wednesday, July 8, 2009

Calling Self Hosted WCF Services from Silverlight

I have an application that self-hosts a WCF service.  Now I want to add an HTTP endpoint to that application and have a Silverlight application call my service.  Sounds easy.

Except that it’s not, because the Silverlight app is trying to do a cross-domain web service call (since the endpoint is self-hosted), and for that to work, the endpoint needs to return a file called clientaccesspolicy.xml when the silverlight app asks for it.  But since my application isn’t running in IIS (and I don’t want it to), returning this file when that HTTP request comes in is not a trivial thing to do.  In fact, I don’t think it can be done.  A self-hosted WCF service is not a web server – just an endpoint.

So I’m a bit stuck, and a bit more perplexed.  There must be a way to call a self-hosted WCF service from a Silverlight application, don’t you think?  Or maybe not, which would be very frustrating, because then I’d either have to do it in JavaScript or I’d need to do some super-nasty webservice-that-calls-a-WCF-service architecture.  And thinking about that just makes me cringe.  But if it’s what I have to do, then I guess that’s what I’ll do.

I don’t like this cross-domain restriction.  I’m sure there’s a good reason behind it, but it seems to create more problems than it solves.

UPDATE: There is, actually, a way to do this – though it’s not as intuitive as you might think.  Check out the solution here.

0 comments: