• Silverlight 2 Beta 2 updates for web services


    We were all jumping for joy when Silverlight 2 beta 1 was released and the ability to connect to services was more readily/easily available to us.  For discoverable services that provided a WSDL we were quickly able to implement them using the Add Service Reference capability in Visual Studio 2008.  Beta 2 brings a few changes to the world of services that you should know about.  I’ll do my best to recap some of them here.

    Generating a WCF Service

    In beta 1 when we created a WCF service for use in Silverlight, we used the “WCF Service” template in Visual Studio (assuming you used Visual Studio).  This was fine and created a standard WCF service for us.  There were a few changes that we had to make to ensure that our Silverlight application could consume it in an acceptable manner.  First, we had to change the binding configuration in ASP.NET web.config from wsHttpBinding to basicHttpBinding as Silverlight only supports that binding type right now.  Secondly, we might have had to add capabilities to enable ASP.NET compatibility support depending on what we were doing with the service.  In beta 2, this process gets a bit simpler for services specifically built for Silverlight.  After you install the tools for Visual Studio, you now get a new item type:

    It is important to note that the WCF Service template is still a perfectly acceptable one to choose, you just have to ensure to make those changes accordingly.  The new Silverlight-enabled WCF Service basically does those for us as well as add the ASP.NET compatibility attributes for us in the code.  Additionally, the traditional interface/implementation is simplified into a single class.  Again, the other ways are still valid, but for services specifically built for Silverlight, this might be an easier route to get them done.

    Cross-domain policy file updates

    Cross-domain restrictions still apply within beta 2 and the same rules apply.  There is one subtle change that is required to your clientaccesspolicy.xml file that is required.  In the allow-from node of the policy file, the attribute http-request-headers is now required.  If your service is an open/public one then specifying “*” is probably acceptable (you’ll have to be the judge of that.  If you only wanted to allow specific headers (besides the blacklisted ones) you can provide those in a comma-separated list and can use wildcards as well.  For example you could use X-MyApp-* if you wanted.

    Another thing to note about the support for Adobe’s crossdomain.xml policy file is one thing we found in interpretation of the policy template.  Previously Flash was a Macromedia product and as such that file is adorned with a DOCTYPE that represents a schema with macromedia in it.  Well, Adobe has changed the schema a little bit and also updated the DOCTYPE to reflect Adobe as the authority.  Right now, Silverlight still expects to validate the macromedia declaration.

    ServiceReferences.ClientConfig

    In beta 1, when you performed the Add Service Reference operation a file named ServiceReferences.ClientConfig was created and had some configuration information in it.  This file, however, wasn’t really used.  In beta 2, this configuration file can be shipped with your XAP and used as configuration.  It provides a subset of WCF configuration.  Refined details of those settings are in the SDK, but I thought it might be helpful to know.

    Change to WebClient

    In beta 1, WebClient was the easiest library to use in accessing non-discoverable services.  One challenge was that it only supported GET verb requests.  In beta 2 WebClient has changed to enable POST verb actions as well.  the UploadStringAsync function will send the request but the endpoint URI must be a URI that accepts the POST verb.

    In addition, WebClient is now callable on a background thread in addition to the UI thread.  This may come in handy for some situations.

    I see these as small but helpful changes.  Most are based on feedback we received from beta 1 customers and community, so thank you for that feedback.  I hope this helps!


    This work is licensed under a Creative Commons Attribution By license.

    Friday, June 06, 2008 9:05 PM

    PostTypeIcon

Comments.

  • snelldl said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    I have not been able to add a service reference to a silverlight application using B2. I used the available WCF tutorial and a video by tim heuer as the methods, as well as trying the new control/wizard. Projects of mine that were able to 'discover' services in B1 are NOT able to in B2.

    Any ideas?

    6/7/2008 6:06 PM
  • timheuer said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    @snelldl: hmm, sounds strange. if you want to email me your projects directly I can try to help. I'm assuming the service project is in the same solution as the silverlight project?

    6/7/2008 7:48 PM
  • snelldl said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    I upgraded a project from b1 to b2 and the web services stopped working. After 12 hours of banging my head, I decided to go through the quick start tutorial on WCF and also duplicate the technique used in one of your videos, as well as trying the new WCF for Silverlight control/wizard you talked about above. The service page can be seen in a browser from the web side, but you can not 'discover' it in the silverlight project. If you put the full reference in the address box and click go, it will find the service. But when you click OK to add the service reference, it gives the error 'Object reference not set to an instance of an object' and it doesn't add the reference.

    I'd be interested to see if you the same problems I did.

    6/8/2008 3:09 AM
  • Synced said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    I'm hitting an issue where I can't reference a service that exposes ADO Entities.

    The following compiler error in Reference.cs occurs:

    Error 1 'System.Runtime.Serialization.DataContractAttribute' does not contain a definition for 'IsReference' ............\Service References\ShopService\Reference.cs

    I have posted it at the SL forum here:
    http://silverlight.net/forums/p/17546/58427.aspx#58427

    6/8/2008 8:09 AM
  • DaveUK said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    I get the

    'Object reference not set to an instance of an object'

    problem when trying to add a Service Reference to an asmx service. This always worked with B1

    Dave
    UK

    6/8/2008 10:29 AM
  • Norm said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    I'm having the same problem with adding web service references with SL2B2 w/VS 2008 SP1.

    6/8/2008 4:05 PM
  • Chris said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Had similar problems with web services above. Bata 2 doesn't seem to recoginse the ServiceReferences.ClientConfig file. Got around the problem by instantiating an Endpoint Address and Binding in code and call the web service with these

    6/8/2008 5:33 PM
  • Rasmus said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    I'm having a similar problem. I can't add a reference to a web service (getting the 'Object reference not set to an instance of an object'). In addition, i also get the error when trying to delete an old reference (added in Beta 1)

    6/9/2008 3:08 AM
  • Rasmus said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Also, i get a "Unable to find service 'DynamicTypeService'. Ensure that the application is installed correctly." when trying to configure the service reference.

    6/9/2008 4:14 AM
  • snelldl said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    I did this and it fixed my wcf problems:

    http://www.itwriting.com/blog/?p=665

    6/9/2008 5:27 AM
  • Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Got bit by the changes in crossdomain.xml and required http-request-headers attribute.

    I've noticed alot of sites like:

    - http://twitter.com/crossdomain.xml
    - http://search.yahooapis.com/crossdomain.xml
    - http://api.flickr.com/crossdomain.xml

    Don't include this attribute. This is going to cause app breakage (specially the Flickr one)...

    6/9/2008 10:12 PM
  • Jeff said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    http://www.itwriting.com/blog/?p=665

    fixed my WCF woes as well.

    6/10/2008 7:19 AM
  • timheuer said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    @Jonas: those sites use the Adobe crossdomain.xml format, for which Silverlight supports a specific format (those that are there are fine). The change was to Silverlight's specific policy format (clientaccesspolicy.xml).

    6/10/2008 8:53 AM
  • Kent said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Based above discussion and this post:
    http://developer.amazonwebservices.com/connect/thread.jspa?threadID=22583&tstart=0

    my understanding is that a SilverLight app cannot talk to Amazon Web Service directly, right? Will Microsoft push Web Service Providers like Amazon to implement ClientAccessPolicy.xml or this might be changed in future release?

    Thanks
    Kent

    6/25/2008 1:10 PM
  • timheuer said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    @Kent: we are working with Amazon to see about updating their files.

    6/25/2008 1:36 PM
  • Kent said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Thanks Tim!

    6/25/2008 3:48 PM
  • KyronSr said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Thank you very much for the informative post. I too was banging my head against the 404 error [even though my tiny webservice was up and running]. It didn't dawn on me that the existence of the policy file was REQUIRED.. duh! :)

    7/2/2008 12:47 AM
  • vchip said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    We are offering data through web services. Recently in order to support beta 2 apps, I updated my clientaccesspolicy file to include http-request-headers="*" attribute. But this broke the beta 1 apps that were earlier working fine consuming our web services.

    <?xml version="1.0" encoding="utf-8" ?>
    - <access-policy>
    - <cross-domain-access>
    - <policy>
    - <allow-from http-request-headers="*">
    <domain uri="*" />
    </allow-from>
    - <grant-to>
    <resource path="/" include-subpaths="true" />
    </grant-to>
    </policy>
    </cross-domain-access>
    </access-policy>

    Are the policies of beta 1 and beta 2 conflicting? Can they not co-exist? Thanks in advance.

    7/3/2008 1:01 PM
  • timheuer said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    @vchip: they cannot co-exist no. beta 1 is no longer supported per the EULA

    7/3/2008 1:13 PM
  • Kent said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Seems Amazon still hasn’t implemented clientaccesspolicy.xml. Not sure how long it’ll take before all of those popular sites (amazon, google, facebook etc etc) implement it…
    I’m still wondering why we need this file though… I can understand if a silverlight app tries to make a cross domain web service call, user should get a security warning. But why does Amazon need a new file to prevent people from accessing its data? You need to provide your Amazon key/id anyway…

    7/4/2008 11:40 AM
  • vchip said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Tim, thanks for the quick reply.

    7/5/2008 8:31 PM
  • Mel said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    A Silverlight sample that works with a WCF self-hosted app is greatly appreciated, especially using an existing MSDN WCF sample.

    The examples I found on MSDN are created using the VS "Web Service Application" project template, which creates ASP.Net apps.

    7/9/2008 9:03 AM
  • timheuer said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Mel: See http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx

    7/9/2008 9:05 AM
  • Ricky said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    I've used WCF-for Silverlight template and can see through browser. But
    If I try to add a service reference to SL application it does not work.

    Basically this web service is behind basic authentication so when I tried to add in vs2008 it has asked for the password but it is not working/ cannot download wsdl.

    I can see WSDL through browser by providing same userid and password.

    i cannot use the svcutil.exe because i could not find command line switch to provide userid, and password... it is making me crazy.

    please help.

    7/16/2008 11:11 PM
  • Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Hi Tim,
    I created a WCF Service using Visual Studio 2008. I then tried invoking this service from a Silverlight 2 Beta 2 app within the same solution. I am not able to do so. Both the WCF Service and the Silverlight project are on the same PC. So I shouldn't have any cross domain issues. I get the following error message:

    An error occurred while trying to make a request to URI 'http://localhost:3862/Service1.svc'. This could be due to a cross domain configuration error. Please see the inner exception for more details.

    I do not know where to go from here. Could you help ?

    Thanks,
    Sudeep

    8/6/2008 8:53 AM
  • Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Hi Tim,
    Thank you very much for the quick responses. After seeing your video that you posted for cross-domain policy problems, I was able to correctly place the clientaccesspolicy.xml file in the right place. Everything has gone on smoothly from there.

    Thanks a bunch,
    Sudeep

    8/6/2008 1:19 PM
  • Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Hoping you might be able to lend some guidance on some issues I'm having with a WCF service and a silverlight application.

    I have a WCF service that is up and running on my local IIS server, http://localhost/Services/MyNewService.svc

    The SVC file points to a dll that implements the service functionality and interface IService.cs and Service.cs.

    I can open a browser and hit the service no problems. I see the WSDL, I am able to hit the service via console application and fetch the information and display the data.

    Having read about cross-domain issues I added a clientaccesspolicy.xml file to the root of my webserver.

    I then created a new Silverlight application and added a service reference to the WCF service on my local machine. I am able to see the methods of the service, and add respective event handlers for the completed events.

    I am hitting a 404 error on the completed event.

    I have used both fiddler and web development helper and am only getting responses of 200.

    I have upgraded to VS2008 SP1, 3.5 Framework SP, and reinstalled the SL SDK, and am at a loss for what could be wrong here. If you could lend any guidance that would be greatly appreciated.

    Thanks.

    8/13/2008 9:16 AM
  • Dmitry K said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Hi Tim,
    Good post, it has helped me to resolve my problem with calling wcf service. Problem was in the http-request-headers attribute and a one stupid typo.
    Guys please check whether you are using
    This typo cost me 2 hours :).

    Thanks.

    P.S. (Sorry for my english. It's not my native language)

    8/20/2008 2:02 PM
  • Dmitry K said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    It seems html tags are not allowed.
    Missed text for previous message:

    grant-to
    resource path="/" instead of resource path="\"
    /grant-to

    P.S. (Sorry for my english. It's not my native language)

    8/20/2008 2:07 PM
  • Nursey said:
    Gravatar
    # re: Silverlight 2 Beta 2 updates for web services


    Yep this post just fixed 8 hours of trouble shooting for me!

    8/23/2008 5:31 AM

Your Reply.

  Comment Form  

Fields denoted with a "*" are required.

*Your name:
Subject:
Your blog:
Your email:  (will not be displayed)
*Your message:

 
Please add 2 and 8 and type the answer here: