Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Example of using WCF with Silverlight 1.1 RSS

5 replies

Last post Feb 26, 2008 09:09 PM by wisecarver

(0)
  • brainbox

    brainbox

    Member

    115 Points

    166 Posts

    Example of using WCF with Silverlight 1.1

    Oct 18, 2007 08:47 AM | LINK

    Is there any official microsoft example of using WCF services with Silverlight 1.1 alpha?

    If anybody knows a good example with source code plz give me a link to this resource.

    Cheers,
    Zakharov Alexey, Microsoft Certified Professional Developer.

    Website: witcraft.ru
    Blog: weblogs.asp.net/AlexeyZakharov/
  • jasonxz

    jasonxz

    Participant

    1787 Points

    557 Posts

    Re: Example of using WCF with Silverlight 1.1

    Oct 18, 2007 04:21 PM | LINK

    I believe, for the time being, that the only method of communication that is supported by SL is JSON serialized web services.  WCF should be supported in later releases and before SL 1.1 goes live.

  • MyMindsOwn

    MyMindsOwn

    Member

    52 Points

    22 Posts

    Re: Example of using WCF with Silverlight 1.1

    Oct 18, 2007 05:46 PM | LINK

    The way I got it to work was by using a proxy to an asmx service in my web application, which is a proxy to the WCF service. This is because Silverlight and WCF don't like each other, so you can use a web application to mediate and make them play nicer (see #3 below). The structure is like this:

    The solution contains a Silverlight 1.1 application, an ASP.NET Futures application and a WCF service project. The ASP.NET Futures application contains an asmx service implementing the WCF service contract and passing through to that service. A proxy class for the asmx service is generated using slwsdl.exe and added to the Silverlight application (See #1 below. Use that proxy in your Silverlight app to call your service methods.) The hookup is completed by adding a Silverlight link to the web application and using the ASP.NET Futures XamlControl to host your Silverlight content.

    Some things to consider about this approach:

    1. You'll need to manually set the Url property of the generated Silverlight proxy to the relative path of the asmx service in the web application. Since the Silverlight content will reside in the web application, the relative Url will resolve to the asmx service. This is how you get around the cross domain calls exception the BrowserHttpWebRequest likes to throw.
    2. You can't debug the service calls in your Silverlight application -- you have to do it from the web application. The Silverlight application won't function independently because it needs the asmx service in the web application. And System.ServiceModel and Silverlight don't like each other, so you can't implement the asmx proxy in Silverlight. At least I couldn't figure out how.
    3. Something about what is happening under the hood fails service methods with multiple arguments. I've seen stuff out there talking about this, but I can't recall the reason. Should be easy enough to find. This is the big ugly for me.

    I can provide a base implementation if you'd like. I'm not sure if this is the best way to do it, but it worked for me and doesn't require too much smoke and mirrors or compromise.

  • Islam Eldemery

    Islam Eldemery

    Member

    6 Points

    4 Posts

    Re: Re: Example of using WCF with Silverlight 1.1

    Feb 26, 2008 07:35 PM | LINK

    Hello, thanks for these ideas,

    I want to ask about how to configure the binding between the asmx service to the wcf and from the silverlight to the asmx if i want to enable callbacks,

    I also ask if you can provide a simple implementation of working source code

    Thanks alot,

  • Bill Reiss

    Bill Reiss

    Contributor

    4973 Points

    947 Posts

    Re: Re: Example of using WCF with Silverlight 1.1

    Feb 26, 2008 07:47 PM | LINK

    Wait for 2.0 beta, it's not that much longer...


    Bill Reiss, Coauthor of Hello! Silverlight
    My blog
  • wisecarver

    wisecarver

    Member

    388 Points

    168 Posts

    Re: Re: Re: Example of using WCF with Silverlight 1.1

    Feb 26, 2008 09:09 PM | LINK

    ...Agreed [;)]