June 2008 Entries
If you want to have your Silverlight control to have a transparent background, then it is simply a question of setting the properties that Mike Snows describes in his tip post.
What had caught me out previously and the reason for this post is that I had used the Background property of the Silverlight control, rather then the correct PluginBackground property. Confusingly this works for the Html control but not the Aspx one. I had in fact filed it as a bug, and perhaps it is because I am not sure we need both of those properties?
Cheers
Ian
Technorati Tags:
Silverlight
Apple just announce MobileMe for push email, contacts and calendars for data in the cloud. Interesting stuff - but the logo? Hmmm.....
==
Cheers
Ian
Technorati Tags:
MobileMe,
Windows Me
For security reasons, the Silverlight version 2 runtime restricts access to certain classes of URLs from the WebClient and HTTP classes in the System.Net namespace.
The main requirement is that the services you want to use should implement either crossdomain.xml (which is the Flash policy file) or clientaccesspolicy.xml (which is the Silverlight one). If the service you want to use does not implement one of these then you can't use Silverlight to access it.
However such restrictions are not present when using WebClient on the server, so you can easily create a bridge service that your Silverlight client can use.
For example you could create a very simple WCF Service in the same web site that will host your Silverlight app as follows:
using System;
using System.ServiceModel;
[ServiceContract]
public interface IFeeds
{
[OperationContract]
string GetFeed(Uri uri);
}
using System;
using System.Net;
public class Feeds : IFeeds
{
#region IFeeds Members
public string GetFeed(Uri uri)
{
WebClient client = new WebClient();
return client.DownloadString(uri);
}
#endregion
}
Note: You need to change the Wcf service binding in web.config so that you use a basicHttpBinding rather than the wsHttpBinding (which is not supported by Silverlight)
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="FeedsBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="FeedsBehavior" name="Feeds">
<endpoint address="" binding="basicHttpBinding" contract="IFeeds">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Now you can add a service reference from your Silverlight application to this Wcf service and use it something like as follows:
private void Button_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.FeedsClient client = new ServiceReference1.FeedsClient();
client.GetFeedCompleted += client_GetFeedCompleted;
client.GetFeedAsync(new Uri("http://timesonline.typepad.com/sports_commentary/atom.xml"));
}
void client_GetFeedCompleted(object sender, ServiceReference1.GetFeedCompletedEventArgs e)
{
TextBlock1.Text = e.Result;
}
Cheers
Ian
We use a simple Friend Feed user control on our home page. We have found this a great way to share "filtered" information that is relevant to our customers.
What we have done is created a FriendFeed account called bbits, which we share things into (via google reader and other feeds).
The user control then picks the friendfeed up and displays this in a gridview.
When we did this FriendFeed didn't have any widgets, which they do have now, (and here) so if you prefer to use those rather than a c# user control go visit those pages now.
Our c# user control can be found below or from here (this also includes a modified version of the c# library produced by friendfeed, that solves a few small issues and bugs)
Cheers
Ian Blackburn
This error had me baffled today, and I could find little reference to it from Google or Live Search.
It was the result of creating a simple WCF Service with two methods as follows and then trying to add a reference to it from Silverlight 2:
[ServiceContract]
public interface IWcfService
{
[OperationContract]
string HelloWorld(string name);
[OperationContract]
List<Person> GetPeople();
}
public class WcfService : IWcfService
{
public string HelloWorld(string name)
{
return "Hello World " + name;
}
#region IWcfService Members
public List<Person> GetPeople()
{
List<Person> people = new List<Person>();
people.Add(new Person() { FirstName = "Fred", LastName = "Bloggs", Age = 23 });
people.Add(new Person() { FirstName = "Fred", LastName = "Smith", Age = 24 });
people.Add(new Person() { FirstName = "John", LastName = "Bloggs", Age = 29 });
return people;
}
#endregion
}
The service config looked good (having changed to a basicHttpBinding - which is the what Silverlight 2 supports:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WcfServiceBehavior" name="WcfService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
contract="IWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
But I kept getting this error. And the other 6 delegates on the course I was delivering were getting exactly the same problem! I kept thinking that this was something to do with Silverlight, but I was barking up the wrong tree. It wasn't until I got on the train home, that it suddenly hit me, I had not marked the Person class with the DataContract and DataMember attributes! This was what was needed to sort it out:
[DataContract]
public class Person
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public int Age { get; set; }
}
Still, in my defence, I think the cause of the error message wasn't that obvious.
Hope this helps someone!
Cheers
Ian
Technorati Tags:
Silverlight,
WCF