Porting to MySpace using Silverlight

I was looking for a simple way to bring an existing web application to MySpace. I wanted to be able to place this app on a Profile page so that visitors could interact with it (similar to the Music and Video players provided by MySpace). My initial thought was to simply use an IFRAME that displayed my application. Unfortunately this turned out to be impossible as MySpace doesn’t allow IFRAMEs to be placed on Profile or Home surfaces.

So how does one quickly turn their HTML application into a MySpace application without rewriting a ton of code? Enter Microsoft Silverlight and the RadHtmlPlaceHolder control from Telerik. MySpace supports Silverlight applications, just like Flash. And with an install base somewhere around 70% now, I decided Silverlight is absolutely a viable option for my app.

The HTML Place Holder control from Telerik allows you to display HTML content within the Silverlight canvas. After checking with MySpace, I was told this was an acceptable use of Silverlight on MySpace.

I started by creating a Silverlight project. It is quite simple really, a single canvas with the HTML Place Holder control on it (set to 100% height and width) . I then added some code to handle the init parameter for the URL to display.

In my App.xaml.cs I added:

[csharp]
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage(e.InitParams);
}
[/csharp]

In my MainPage.xaml.cs I added:

[csharp]
public MainPage(IDictionary<string, string> initParams)
{
InitializeComponent();
radHtmlPlaceholder1.SourceUrl = new Uri(initParams["URI"]);
}
[/csharp]

That is the entirety of the Silverlight application. Pretty simple. I told Silverlight that the host for my Silverlight application was my existing web application, so it created the host automatically for me. I didn’t need to do anything else.

In MySpace, I added the following code to call my new Silverlight application:

[js wraplines=”false”]
<div id="content"></div>

<script type="text/javascript">
var contentElement = document.getElementById("content");
var initValue = "URI= <URL TO DISPLAY>";

var object = ‘<object data="data:application/x-silverlight-2," height="100%" type="application/x-silverlight-2" width="100%"> ‘
object = object + ‘<param name="source" value="<URL TO XAP FILE>" /><param name="onError" value="onSilverlightError" /> ‘
object = object + ‘<param name="background" value="Transparent" /><param name="minRuntimeVersion" value="4.0.50401.0" /><param name="autoUpgrade" value="true" /> ‘
object = object + ‘<param name="windowless" value="true" /><param name="enableHtmlAccess" value="true" /><param name="initparams" value="’ + initValue + ‘" /> ‘
object = object + ‘<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration: none"> ‘
object = object + ‘<img alt="Get Microsoft Silverlight" src="http://go.microsoft.com/fwlink/?LinkId=161376" style="border-style: none" /> </a> </object> ‘
contentElement.innerHTML = object;
</script>
[/js]

Hopefully this helps someone else out there. Feel free to contact me with any questions.

Web Search with Lucene.NET

I’ve been working with Lucene.NET and a project called Seekafile based on it for the last few days.

Seekafile runs as a windows service that builds a Lucene index in the background. You can then use it to build Windows and Web clients that search that index.

Using a few lines of code I was able to quickly build an index of our intranet (including text, html, Word documents, etc) and a simple web site to search it.

This all started after I tried to use the Microsoft Index Service. I was able to get it up and running quick enough but the search capabilities were pretty limiting. What I wanted was "Google" style searching and the Index Service doesn’t seem capable of doing it (at least not without more of a development effort invested into it).

There were a few issues with Seekafile, namely that the management UI is somewhat limited (adding index directories is tedious for example) and you cannot exclude directories or filter what is added to the index. But other than that it does exactly what I needed – add a simple searchable index to our intranet.

Overall I though it worked really well and it has running without incident for 24 hours.

Web Service Purgatory

Well, I’m out of Web Service Hell.Christian Weyer pointed me in the right direction and I had my first Web Service working pretty quickly.

It turns out that the dataset is only included in the WSDL if it is actually being returned by a function. Simply including it in the project, even if it is used in the code(as mine was), does not mean it will be made visible to the outside world.

This does make some sense as you wouldn’t typically want to see a bunch of internal components of the web service unless those components could be used by the client application. Now that I understand this little rule, things are much clearer now. Of course, it would be nice to have had this documented someplace. But hey, where would the adventure be in that?

I’m still working though some issues in my head (data collisions and exception handling for example) so I’m not quite in Heaven yet, but I am comfortable in purgatory. 🙂

Thanks again Christian.

Web Service Hell

Let me warn you that this posting may be a little incoherent and I apologies for that. You see, my brain is currently lying on the floor next to me. It seems that in a fit of frustration it jumped for it.

< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

This week I decided to join the rest of the .< ?xml:namespace prefix = st2 ns = "urn:schemas-microsoft-com:office:smarttags" />NET world and try my luck at Web Services. They seemed simply enough. Heck, they even include the world “Simple” in the protocol name! So how much trouble could this cause me anyway? Ug….

 

I installed the TaskVision sample and opened it up. Everything was extremely easy to understand. In fact, I was blown away by how seamless it all fit together. There seemed to be very few “hoop jumps” in their code.

 

After gaining some confidence from TaskVision, I started a new project.

 

I added an ASP.NET Web Service and a Windows Application to consume it. I quickly went about adding a Dataset to the Web Service project and added some code to return that dataset to the client. There was nothing special about it, just a “SELECT * FROM customer” against Northwind. I tested the Web Services via the integrated test web page thingy (very nice btw) and got back all my Northwind customers.

 

Soon after this, my brain took the suicidal leap.

 

Now that I have this lovely Web Service, I made a Web Reference to it from my client application. But something strange happened. While the class that returns the dataset was there, the dataset itself was not. I took another look at TaskVision and found that they were available in their Web Service. So what was going on here? Why can’t I access the dataset?

 

I’ve now been Googleing for 3 days and have found nothing on this. So either I’m an idiot (very possible, even probable) or I’m trying to do something abnormal here (also very possible).

 

Anyone want to help me get my brain back into my head?