tags:

views:

47

answers:

2

Hey, Can someone tell my why when I have wcf contract:

    [ServiceContract]
public interface IService1
{
    [OperationContract]
    string TestGetName();
}

and implementation

 public string TestGetName()
    {
        return "Kasia";
    }

When I try consume it in Console app I can do just that:

    Service1Client client = new Service1Client();
    Console.WriteLine((client.TestGetName()));

but in Silverlight I must use that way :

            Service1Client clientTest = new Service1Client();
            clientTest.TestGetNameCompleted += new EventHandler<TestGetNameCompletedEventArgs>(clientTest_TestGetNameCompleted);
            clientTest.TestGetNameAsync();
    void clientTest_TestGetNameCompleted(object sender, TestGetNameCompletedEventArgs e)
    {
            this.dataGridChild.DataContext = e.Result;

    }

Why in SL I don't see this first short solution, but only this with Event handlers? Or better... why in Console app I can choose synchro operation generation and in SL I must use Generate asynchronous operations... :/

+1  A: 

Silverlight does not support synchronous calls (which is what you're doing in your console app).

Update: http://forums.silverlight.net/forums/p/34531/104526.aspx "The main point is that it looks like synchronous behaviour was removed on account of not being supported by all browsers."

kojo
+2  A: 

A synchronous call would stop the Silverlight UI thread and possibly the executing environment, i.e. the browser. To prevent this, only asynchronous calls are allowed.

Of course this is something unusual at first, but in the long run it is actually helpful to decouple the view and service layer.

Ozan