2009-12-13 149 views
1

不知道我是否做错了什么......但我试图实现可以从WCF调用的WCF服务。我实现了客户端上的异步模式,这里的电话是什么样子:从Silverlight挂起的WCF呼叫挂起

BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); 
EndpointAddress endpointAddress = new EndpointAddress(AccountServiceURL); 
var personService = new ChannelFactory<IAccountService>(basicHttpBinding, endpointAddress).CreateChannel(); 

var result = personService.BeginRegister(username, password, email, null, null); 
personService.EndRegister(result); // <-- failing here 

它挂在“EndRegister”呼......它只是坐在那里,什么都不做。而firefox.exe变得没有响应。由于我在方法调用中有一个断点,因此服务器似乎不会接收到调用。也许有人可以看到我做错了什么?

合同看起来像这样在客户端上:

[ServiceContract] 
public interface IAccountService 
{ 
    [OperationContract(AsyncPattern = true)] 
    IAsyncResult BeginRegister(string username, string password, string email, AsyncCallback callback, Object state); 

    void EndRegister(IAsyncResult result); 
} 

像这样在服务器上:

[ServiceContract] 
public interface IAccountService 
{ 
    [OperationContract] 
    void Register(string username, string password, string email); 
} 

回答

2

如果你拨打的UI线程(你可能是)上,然后它会让你的Silverlight运行时崩溃。这最后一个电话......

personService.EndRegister(result); 

...是要阻止,并在我的经验Silverlight运行时真的,真的很讨厌当UI线程阻塞上的IO呼叫这样得到。您应该对事件或回调作出响应,然后在该事件或回调处理程序中进行EndRegister调用。

+0

就是这样!谢谢杰森 – 2009-12-15 00:55:36

0

据我所知,这是因为Silverlight的WCF基础结构根本不使用ThreadPool。因此,要的BeginXXX的调用是不是真的异步调用...

我也迷迷糊糊在这个非常奇怪的行为:

var ar = svc.BeginXxx(null, null); 
var response = svc.EndXxx(ar); 

和我们的应用程序handgs。