Skip to main content
Home Forums Silverlight Programming Programming with .NET - General HttpListener & Silverlight object = Error Code: 2104
2 replies. Latest Post by CARNIBAL06 on September 17, 2009.
(0)
CARNIBAL06
Member
0 points
5 Posts
09-16-2009 6:01 AM |
Hi all,
I'm trying to developp a mini web server with HttpListener object.
When a request is received, my class send an html page with only source without xap.
In my browser, i have a blank page with a Silverlight Error : Code 2104, Could'nt download Silverlight Application.
This is my class code :
static HttpListener listener; static void Main(string[] args) { listener = new HttpListener(); listener.Prefixes.Add("http://+:1337/vwm/"); listener.Start(); if (!HttpListener.IsSupported) { Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class."); return; } while (listener.IsListening) { IAsyncResult result = listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener); Console.WriteLine("Waiting for request to be processed asyncronously."); result.AsyncWaitHandle.WaitOne(); Console.WriteLine("Request processed asyncronously."); } listener.Close(); } public static void ListenerCallback(IAsyncResult result) { HttpListener listener = (HttpListener)result.AsyncState; // Call EndGetContext to complete the asynchronous operation. HttpListenerContext context = listener.EndGetContext(result); HttpListenerRequest request = context.Request; // Obtain a response object. HttpListenerResponse response = context.Response; response.ContentType = "text/html"; response.KeepAlive = true; // Construct a response. using (FileStream fs = new FileStream(@"index.htm", FileMode.Open)) { using (StreamReader reader = new StreamReader(fs)) { string responseString = reader.ReadToEnd(); byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); // Get a response stream and write the response to it. response.ContentLength64 = buffer.Length; System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); // You must close the output stream. output.Close(); } } }
And my test html page :
<html>
...<body> <form id="form1" runat="server" style="height:100%"> <div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="/SilverHelloWorld.xap"/> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="3.0.40624.0" /> <param name="autoUpgrade" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/> </a> </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div> </form></body></html>
So, do you know what is the procedure to fix it ? How and where i have to include the xap file in my response ?
Regards,
Guillaume
ken tucker
All-Star
16334 points
2,498 Posts
09-16-2009 6:44 AM |
http://silverlight-help.com/Tips/KenTucker/09-07-15/Silverlight_3_Could_Not_download_the_silverlight_Application.aspx
09-17-2009 6:41 AM |
Thanks Ken for your reply but i had an other type of mistake : my webserver didn't listen on the correct url.
Now, i can display my html page and download the silverlight file, but i have an exception "Silverlight Error : Check Manifest .."
I searched on internet and different solutions don't work for me (rename the xap to zip, check the AppManifest.xaml ...)
I aleardy checked and all is OK.
Do you have an onther idea ?