Actually, this may be a better example: http://msdn.microsoft.com/en-us/library/cc681221.aspx
I've modified the msdn example above to support .html and .xap files:
With this your Silverlight App can be accessed via a URL such as: http://localhost:8000/Service/Files/LoadXap.html
HTML snippet:
<div id="silverlightControlHost">
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">
<param name="source" value="YourSilverlightAppHere.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
</object>
</div>
WCF Code:
// define the service contract
[ServiceContract]
public interface IFileHost
{
[OperationContract, WebGet(UriTemplate = "Files/{filename}")]
Stream Files(string filename);
}
// implement the service contract
public class Service : IFileHost
{
public Stream Files(string filename)
{
Stream stream = (Stream)new FileStream(filename, FileMode.Open);
//Set the correct context type for the file requested.
int extIndex = filename.LastIndexOf(".");
string extension = filename.Substring(extIndex, filename.Length - extIndex);
switch(extension)
{
case ".html":
case ".htm":
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
break;
case ".xap":
WebOperationContext.Current.OutgoingResponse.ContentType = "application/x-silverlight-2-b2";
break;
default:
throw(new ApplicationException("File type not supported"));
}
return stream;
}
}
class Program
{
static void Main(string[] args)
{
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
host.AddServiceEndpoint(typeof(IFileHost), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());
host.Open();
Console.WriteLine("Service is running");
Console.Write("Press ENTER to close the host");
Console.ReadLine();
host.Close();
}
}