Hi,
I'm learning to use HttpListenerRequest/Response.
When i receive a request, i want to send a html page with a silverlight object.
I define my source with a html <object> but, when i try to display my page, i get a blank page.
Have you an idea ?
My code :
static
void
Main(string
[] args)
{
HttpListener listener = new
HttpListener();
listener.Prefixes.Add("http://+:1337/vwm/"
);
listener.Start();
IAsyncResult result = listener.BeginGetContext(new
AsyncCallback(ListenerCallback), listener);
// Applications can do some work here while waiting for the
// request. If no work can be done until you have processed a request,
// use a wait handle to prevent this thread from terminating
// while the asynchronous operation completes.
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;
// Construct a response.
string
responseString = "<html><body>"
+ "Test <object data=\"
data:application/x-silverlight-2,\" type=\"
application/x-silverlight-2\" width=\"
100%\" height=\"
100%\">"
+ "<param name=\"
source\" value=\"
Groy.VideoManager.Prototype.xap\"/>"
+ "<param name=\"
background\" value=\"
white\" />"
+ "<param name=\"
minRuntimeVersion\" value=\"
3.0.40624.0\" />"
+ "<param name=\"
autoUpgrade\" value=\"
true
\" />"
+ "</object>"
+ "</body></html>"
;
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();
}
Regards,
Carnibal