Hosting Silverlight and WebService

Apr 7, 2009 at 8:52 AM

I have a Silverlight-Project in Visual Studio 2008:
- SilverlightClient (this calls the WebService Service.svc)
- SilverlightClient.Web (this project contains a WebService Service.svc)
Is it possible to host such a configuration under C# Web Server? And how? Is there any sample or tutorial?
I've spent now some days to get it running, but no way, doesn't work. Well I'm a newbie with setting up web servers.

My code for the Web Server is:

string basePath = ConfigurationManager.AppSettings["basePath"]; 
string baseUrl = ConfigurationManager.AppSettings["baseUrl"];
string port = ConfigurationManager.AppSettings["port"];
string ipAdr = ConfigurationManager.AppSettings["ipAdr"];
IPAddress ipAddress = IPAddress.Any;
if (!ipAdr.Equals(string.Empty))
{
     
IPAddress.TryParse(ipAdr, out ipAddress);
}
try
{
    server =
new HttpServer.HttpServer(); 
    
FileModule fm = new FileModule(baseUrl, basePath); 
    fm.AddDefaultMimeTypes();
    fm.MimeTypes.Add(
"manifest", "application/manifest"); 
    fm.MimeTypes.Add(
"dll", "application/x-msdownload");
    fm.MimeTypes.Add(
"application", "application/x-ms-application"); 
    fm.MimeTypes.Add(
"xbap", "application/x-ms-xbap"); 
    fm.MimeTypes.Add(
"deploy", "application/octet-stream"); 
    fm.MimeTypes.Add(
"xps", "application/vnd.ms-xpsdocument"); 
    fm.MimeTypes.Add(
"xap", "application/x-silverlight-app"); 
    fm.MimeTypes.Add(
"xaml", "application/xaml+xml"); 
    fm.MimeTypes.Add("svc", "text/xml; charset=utf-8");
    server.Add(fm);
    server.Start(ipAddress, 
    int.Parse(port));
}
catch (Exception ex)
{
    Console.WriteLine(string.Format("Couldn't start webserver: {0}", ex.Message)); 
 }
 
Console.WriteLine("Webserver started at:"); 
 
Console.Write(ipAddress.ToString()); 
 
Console.Write(":"); 
 
Console.WriteLine(port); 
 
Console.WriteLine("Stop by pressing any key"); 
 
Console.Read(); 
 server.Stop();

 


This way, I get an error stating, that a name may not start with "%".
The Service.svc looks like this:

<%@ ServiceHost Language="C#" Debug="true" Service="SilverlightWcfClient2.Web.SilverService" CodeBehind="SilverService.svc.cs" %>

I think I'm missing some parts but have no idea where to start.
Any help would be appreciated.

Regards
Andreas
Coordinator
Apr 7, 2009 at 1:15 PM
That's a ASP.Net string. You need to create a ASP.Net module for the webserver to get that working. Check Cassini webserver for example.