简体   繁体   English

WCF服务的使用差异-控制台vs Silverlight

[英]difference in consume WCF service - Console vs Silverlight

Can someone tell my why when I have wcf contract: 谁能告诉我为什么有wcf合同:

    [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 : 但是在Silverlight中,我必须使用这种方式:

            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? 为什么在SL中我没有看到第一个简短的解决方案,而只有事件处理程序显示了? Or better... why in Console app I can choose synchro operation generation and in SL I must use Generate asynchronous operations... :/ 或者更好...为什么在控制台应用程序中我可以选择同步操作生成,而在SL中我必须使用生成异步操作...:/

A synchronous call would stop the Silverlight UI thread and possibly the executing environment, ie the browser. 同步调用将停止Silverlight UI线程,并可能停止执行环境,即浏览器。 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). Silverlight不支持同步调用(这是您在控制台应用程序中正在执行的操作)。

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." 更新: http : //forums.silverlight.net/forums/p/34531/104526.aspx “主要要点是,由于所有浏览器均不支持同步行为,因此似乎删除了同步行为。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM