Exposing/Consuming RSS/ATOM using WCF 3.5 & Silverlight 2

Play Exposing/Consuming RSS/ATOM using WCF 3.5 & Silverlight 2

The Discussion

  • User profile image

    I don't think there is necessarily a right or wrong answer here.  I think it is a bit of a stretch to suggest I have declared request improperly.  It would be more accurate to say that I have declared request in a way that you dislike for valid reasons.  You make some really good points about the side effects of using var.  I appreciate you making these points because it is very important for people to understand the side effects you mention.  Unfortunately, I can't cover every detail about all the technology in use in a screencast/demo.  If I did, the screencast would have been at least twice as long:).

    You may be right about laziness.  I find myself using var in a number of scenarios I suspect you would dislike.  Maybe I am using it so much because I’ve done quite a bit of JavaScript/AJAX programming of late and it has become a habit.  Who knows?  I think one could argue a number of technologies such as intellisense, code snippets, and many more have made me a lazier programmer over the years.  I surely know that I can't code in notepad or vi like I used to because of my dependency on both IDE and language features.  Then again, it is also fair to say that the productivity gains outweigh the dependency on the features. 

    With the var keyword, it seems the documentation at https://msdn2.microsoft.com/en-us/library/bb383973.aspx would somewhat support your statements since it says “It is recommended to use var only when it is necessary, that is, when the variable will be used to store an anonymous type or a collection of anonymous types.”  However, like any documentation, it is a recommendation.  I still believe the use of var is a matter of preference.  Am I misusing the var keyword?  That’s in the eye of the beholder.  I  know where you stand:). 

  • User profile image
    Thanks for the screencast, it's always nice to see an end-to-end example. The new WCF 3.5 features look great.

    Having said that...

    var request = new WebClient();

    ?? Way to promote terrible programming practices.
  • User profile image
    Do you mind explaining why you believe this is a terrible programming practice?  I can guess that you might think the "var" keyword means that "request" is a variant.  Not so.  What you are seeing is a new feature of C# 3.0 called type inference.  The variable "request" is strongly typed.  In this case, "request" is of type WebClient.  Essentially, the way it works is the compiler evaluates what's on the right hand side of the equals sign and ensures that the variable on the left hand side is typed appropriately.

    You can see https://msdn2.microsoft.com/en-us/library/bb383973.aspx for more details. 

    Personally, I think using the var keyword is a matter of preference, but not a terrible programming practice as you suggest.  The beauty is that the following two lines of code are identical to the compiler:

    var request = new WebClient();
    WebClient request = new WebClient();
  • User profile image
    The var keyword was invented in order to support dynamic types, not to replace the declaration of every local variable.

    The reason I dislike it is because I believe it promotes laziness and needlessly obfuscates the code. The difference between var request = new WebClient(); and WebClient request = new WebClient(); is negligable, so why not declare it properly?

    Take these examples:

    var provider = providerFactory.Create();
    var customer = base.CreateCustomer();

    As a developer seeing this code for the first time, what type is provider/customer? The only way of knowing is by looking up the declaration of Create/CreateCustomer. For the sake of a few keystrokes, you have made the code considerably harder to maintain.

    Additionally, the general argument for var seems to be that the compiler and VS intellisense will inferring the type for you, but that doesn't help me if I am viewing it outside devenv (eg. comparing two versions of a source file in subversion).
  • User profile image
    Hi, Could you possibly make another video on RSS please?? More details on Streaming Video and all that using RSS or WCF?? Thanks in advance
  • User profile image

    I need to create a custom RSS feed which would access a bunch of sales data from the database and consume from my silverlight 3 app.  I followed your video.  Everything works fine when I run from within the syndication library project. But when I try to consume the feed from silverlight app, it just doesn't seem to work. I get System.Security.SecurityException. So I placed the clientaccesspolicy xml at the silverlightapp.web project. Still doesn't seem to work. Do I need to host this syndication library on IIS? By default, it seems to be self hosted and I see that in your demo, you are hosting your feed on feedburner.  Do I need to create silverlight enabled WCF somehow? Also, I was wondering about the "Design_Time_Addresses" in the generated url - http://localhost:8731/Design_Time_Addresses/myLibrary/Feed1/ ?


    Thanks in advance...

  • User profile image
    Ayub Patel

    How do you expose your RSS feeds Created in Video on IIS 6. In our case we have IIS6 with https as protocol. How can we expose the RSS feed so user can trype some thing like this https://www.test.com/Design_Time_Addresses/myLibrary/Feed1/ and gets the Rss feed?

  • User profile image

    @keydet: Ahh help!  This tutorial was sooooo close to a problem I am trying to solve.  You built the WCF service to return the AtomFeedFormatter (or RSS) types.  PERFECT.  You created a Silverlight control to get the RSS. PERFECT.  However, your code example does not consume the WCF service to call the 'CreateFeed()' method.  You hardcoded calling the RSS feed URL directly in your Silverlight sample control and bypassed the WCF service.


    I have a WCF service my Silverlight app is consuming almost identical to yours.  The problem is when consuming the WCF service, the wired up 'Completed' event in the Silverlight control that calls the WCF method, gets back CompletedEventArgs of type 'ArrayOfXElement' which is a list of System.Xml.Linq.XElement objects. This is the type that is translated from the serialized feed returned from WCF via the AtomFeedFormatter return type.  How in the heck do I get e.Result of type ArrayOfXElement back into a SyndicationFeed or SyndicationItem object?? 


    I bet if you consumed your WCF service you created instead of calling that hardcoded URL in your Silverlight control, you would have the same issue.  And you can NOT override the type returned in the 'Advanced' properties upon consuming the WCF service.  Regardless of type selected (ObservableCollection for example) the AtomFeedFormater type returned from WCF gets translated into an ArrayOfXElement.


    How do I get this ArrayOfXElement type back into a SyndicationFeed, so I too can bind it to my .ItemsSource() property on my Silverlight control??


    Thank you!!

Add Your 2 Cents