Second Stanza

June 19, 2010

WCF Client Functionality and Silverlight

Filed under: Silverlight, WCF — dfbaskin @ 10:22 pm

I’ve been looking into Windows Communications Foundation (WCF) functionality, specifically focusing on client features for .NET and Silverlight clients, as a foundation for creating business applications.

So why wouldn’t I just use the WebClient or HttpWebRequest classes? These classes are simple to understand and use. And they don’t introduce the complexity of the WCF framework.

This is true, of course, but WCF offers flexibility that business applications require to implement additional management and interoperability features. Specifically, WCF offers a host of extensibility points that business applications can make use of, such as custom validation, service logging, and data manipulation.

This flexibility is also important where business applications have to rely on outside services. Third-party REST and SOAP services are more ubiquitous and integrating with these services is a common business requirement. These services are a "black box" and your application must manage change that is beyond your control.

Here are a few links to information related to WCF client functionality:

So I hope to post some code examples soon exploring some aspects of WCF client programming.

July 25, 2009

Security Exception on Silverlight Client when Calling WCF Service

Filed under: Silverlight, WCF — Tags: — dfbaskin @ 12:14 pm

I kept getting a SecurityException when calling from my Silverlight client to a WCF service. I had double-checked WCF settings (I used basicHttpBinding, which is what Silverlight supports). I had created clientaccesspolicy.xml and crossdomain.xml files on the root of my web site. The meta data came up correctly for my service. Via Fiddler, I saw that the clientaccesspolicy.xml file was being retrieved successfully. But the call to the actual service never happened (the SecurityException was generated first).

While researching this error, I found this post. The solution worked for me, but it also bugged me. I found it hard to believe that the clientaccesspolicy.xml file just simply didn’t work.

And I was right. I did manage to get the clientaccesspolicy.xml to work. According to this MSDN article, the contents of the clientaccesspolicy.xml file might look like this:

<?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>

The problem turns out to be the encoding. When I removed the attribute, encoding=”utf-8″, the Silverlight client happily called the service with no problem.


Ok, scratch that. I tried to reproduce the original problem by adding the encoding back to the clientaccesspolicy.xml, and … it works. I tried resetting the IIS server and clearing the browser cache, and now I can’t get it to fail again.

So, I’m still scratching my head about this.

Create a free website or blog at WordPress.com.