Suppose you have a nice Console Application. Suppose you want to host a WCF service. And suppose you want to create a fancy Silverlight app that consumes this WCF service.
You’ll soon discover that something isn’t working as expected…long story short, the client app is looking for a ClientAccessPolicy.xml file. And why in the world shouldn’t we provide it?
Here’s what you have to do:
1) Create another WCF Service, call it CrossDomainService
2) Add this method:
[WebGet(UriTemplate = "ClientAccessPolicy.xml")]
public Message GetClientAccessPolicy()
using (var filestream = File.Open(@"ClientAccessPolicy.xml", FileMode.Open))
var buff = new byte[filestream.Length];
filestream.Read(buff, 0, (int)filestream.Length);
var stream = new MemoryStream(buff);
return Message.CreateMessage(MessageVersion.None, "", XmlReader.Create(stream));
3) Add a ClientAccessPolicy.xml file to your project (you may find thousand of examples online…look at this maybe)
4) Add this to your app.config:
<endpoint address="" behaviorConfiguration="CrossDomainServiceBehavior"
binding="webHttpBinding" contract="CrossDomainService" />
<add baseAddress="http://localhost:12345/" />
Obviously make sure that the baseAddress has the same root as the WCF Service you want to expose at first 🙂