views:

290

answers:

1

I have a silverlight application that needs to use multiple WCF services. The endpoints (urls) of the services cannot be hardcoded inside the silverlight application or the configuration file. They must be queried from a Service Registry which is itself a WCF service. The problem is that I have to use an async call to query the service endpoint before I can create an instance of the real service proxy. I can't think of a good way to wait for the response or block calls to real service. What is the best way to use the Service Registry / Service Locator pattern from whichin a silverlight application?

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();
A: 

Hi,

Either you can cache the lookup from the registry, or you can do the lookup each time you want to communicate with a service (normally not recommended).

In the code snippet you've supplied, you're subscribing to the GetServiceCompleted event. It is in that even handler (in your case, the lambda expression) that you will need to either cache the lookup and/or initiate the call to the service.

HTH,

--larsw

larsw