使用 WCF 服务的 Silverlight 代理客户端确定通道中的错误
我正在使用异步模式为 WCF 服务创建 Silverlight 代理客户端:
public class ProductService : ClientBase<IProductService> {
public event EventHandler<DataEventArgs<Product>> GetProductCompleted;
public void GetProductAsync(string productName) {
IAsyncResult asyncResult = Channel.BeginGetProduct(productName, GetProductCallback, null);
}
private void GetProductCallback(IAsyncResult asyncResult) {
Product product = Channel.EndGetProduct(asyncResult);
if (GetProductCompleted != null)
GetProductCompleted(this, new DataEventArgs<Product>(product));
}
}
如何知道在对服务执行请求期间通道中是否发生错误?
I'm creating Silverlight proxy client for WCF service using async pattern:
public class ProductService : ClientBase<IProductService> {
public event EventHandler<DataEventArgs<Product>> GetProductCompleted;
public void GetProductAsync(string productName) {
IAsyncResult asyncResult = Channel.BeginGetProduct(productName, GetProductCallback, null);
}
private void GetProductCallback(IAsyncResult asyncResult) {
Product product = Channel.EndGetProduct(asyncResult);
if (GetProductCompleted != null)
GetProductCompleted(this, new DataEventArgs<Product>(product));
}
}
How can I get know if an error occurred in the channel during performing request to the service?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EndGetProduct
应该在调用时抛出错误,因此在它周围放置一个try..catch
。The
EndGetProduct
ought to throw the error when called, so place atry..catch
around it.