Twitter Updates

    follow me on Twitter
    Showing posts with label WCF. Show all posts
    Showing posts with label WCF. Show all posts

    March 28, 2009

    Make Silverlight 3, WCF and Azure work together

    Recently, I'm working on a project which is composed of a Silverlight 3 Application and a WCF service, hosted by Windows Azure. I encountered a bunch of issues and it's very hard to find the solution. The process is painful, but eventually I solved all of them. Maybe there will be some new issues coming up, but it's good so far. I want to list the major issues and related solutions in case others may look for them as well.

    1. At the very beginning, I saw this.

    Warning 1 The element cannot contain white space. Content model is empty. D:\Azure\SilverlightApplication1\SilverlightApplication1\ServiceReferences.ClientConfig 7 99 SilverlightApplication1

    Warning 2 The element 'httpTransport' cannot contain child element 'extendedProtectionPolicy' because the parent element's content model is empty. D:\Azure\SilverlightApplication1\SilverlightApplication1\ServiceReferences.ClientConfig 8 26 SilverlightApplication1

    http://localhost:63165/Service1.svc" binding="customBinding"

    bindingConfiguration="CustomBinding_Service1" contract="ServiceReference1.Service1"

    name="CustomBinding_Service1" />

    I got the solution from Jimmy Lewis.

    Gary, I think it's due to the section:

    Can you try removing the element and making the element self-closing? I haven't figured out what causes this to be generated incorrectly yet.


    2. Generating proxies
    Out of the box, using Add Service Reference or svcutil to generate a proxy to a service hosted either in the development fabric or the cloud fabric will fail. The following workaround can be used:
    1. Host the service either in the Visual Studio ASP.NET Development Server or your local IIS instance
    2. Use that instance to genereate a proxy
    3. Modify the endpoint address of the generated proxy to point to the correct location (either in the development fabric or the cloud fabric)

    3. Address filter mismatch
    At runtime, WCF services may return the following error: The message with To 'http://127.0.0.1:81/Service.svc' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree. The error can be corrected by applying the following attribute to the service class.

    [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]

    4. Specifying a relative service address
    Normally when adding a service reference, Silverlight will generate a .clientConfig file containing the address of the service. This config file gets pacakged as part of the Azure service and cannot be edited as the service moves from the development fabric, to staging in the cloud fabric, to production in the cloud fabric. This poses a problem since the hardcoded service address will change between these three locations. To use a relative address, you can use the following workaround:
    1. Delete the .clientConfig file
    2. Recreate the appropriate binding in code, for example: Binding customBinding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
    3. Use this method to specify a relative service address: EndpointAddress address = new EndpointAddress(new Uri(App.Current.Host.Source + "/../../Service.svc/binary"));
    4. Pass the binding and address to the proxy constructor: ServiceClient proxy = new ServiceClient(customBinding, address);

    Enjoy.