Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / C#

Synchronous WCF Service Calls with Silverlight

Rate me:
Please Sign up or sign in to vote.
5.00/5 (13 votes)
16 Mar 2010CPOL2 min read 71.6K   949   34  
How to make TRUE sync call in Silverlight
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Threading;

namespace DanielSyncIsNotAMythInSilverlight.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class DanielService : IDanielService
    {
        // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
        // To create an operation that returns XML,
        //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
        //     and include the following line in the operation body:
        //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
        [OperationContract]
        public string DoWork(string name)
        {
            Thread.Sleep(3000);
            // Add your operation implementation here
            return string.Concat(name, " rulez da world");
        }

        [OperationContract]
        public string DoWorkWithTwoParams(string name, string name2)
        {
            Thread.Sleep(3000);
            // Add your operation implementation here
            return string.Concat(name, " and ", name2, " rulez da world");
        }

        // Add more operations here and mark them with [OperationContract]
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Viablue - GraphicStream
France France
I spent most of time on Silverlight, Xna (where i am MVP) and ADO.Net Data Services.

Comments and Discussions