.NET Framework Bookmark and Share   
 index > .NET Framework Networking and Communication > Return a silverlight object in a HttpListenerResponse
 

Return a silverlight object in a HttpListenerResponse

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
CARNIBAL
You'll probably want to send back some HTTP headers. e.g.

response.ContentType ="text/html"; //etc


Compare what you send back with what a browser sends back using Fiddler https://www.fiddler2.com/fiddler2/or a sniffer e.g. http://blogs.technet.com/netmon/
http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
Alan J. McFarlane
Hi,


Now i can display the html page, download the xap file but i have an exception in IE "Silverlight Error : Check Manifest ..."

I already tried to check my AppManifest.xaml to correct errors, but all is OK.


Do you have any idea ?


Regards,
Guillaume
CARNIBAL

You can use google to search for other answers

Custom Search

More Threads

• Symbol in front of GBP Pound Sign - £
• Untagged Thread?
• transactions in msmq 3.0
• UseLess? Is DirectorySearcher.PropertiesToLoad UseLess?
• .NET Socket implementation
• multipart form post (File Upload) to a web site
• Using default credential for sending message with SmtpClient
• Code for sending EMAIL is not working.
• Visual Studio could not locate a schema for this document.
• Remotely view of window of an application