开发者

difference in consume WCF service - Console vs Silverlight

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((clie开发者_运维问答nt.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... :/


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.


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."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜