我有一个需要使用多个 WCF 服务的 silverlight 应用程序。服务的端点(url)不能在 silverlight 应用程序或配置文件中硬编码。必须从本身是 WCF 服务的服务注册表中查询它们。问题是我必须先使用异步调用来查询服务端点,然后才能创建真实服务代理的实例。我想不出等待响应或阻止对实际服务的调用的好方法。在 silverlight 应用程序中使用 Service Registry / Service Locator 模式的最佳方式是什么?
var registry = new ServiceRegistryClient("http://localhost/ServiceRegistry.svc");
string url;
registry.GetServiceCompleted += (s, e) => url = e.Result;
registry.GetServiceAsync("MyService");
// now I want to create MyService, but I must wait somehow until url is returned
var myService = new MyServiceClient(url);
myService.DoSomethingAsync();