I am in the middle of a Silverlight application, and I have a function that should call a web service and using the result completes the rest of the function.
My problem is that I usually made a synchronous call to the web service, got the result and using it, which was executed using the function. Since Silverlight does not support synchronous web service calls without additional custom classes to simulate, I suggest that it is best to go with the async stream rather than deal with it. So my question is about what is the best design pattern for working with asynchronous calls in a program stream.
In the following example, I want to use the myFunction TypeId parameter depending on the return value of the web service call. But I do not want to call the web service until this function is called. How can I change my code to allow an asynchronous call?
string _myPath;
bool myFunction(Guid TypeId)
{
WS_WebService1.WS_WebService1SoapClient proxy = new WS_WebService1.WS_WebService1SoapClient();
proxy.GetPathByTypeIdCompleted += new System.EventHandler<WS_WebService1.GetPathByTypeIdCompleted>(proxy_GetPathByTypeIdCompleted);
proxy.GetPathByTypeIdAsync(TypeId);
if (myPath == "\\Server1")
{
}
}
void proxy_GetPathByTypeIdCompleted(object sender, WS_WebService1.GetPathByTypeIdCompletedEventArgs e)
{
string server = e.Result.Server;
myPath = '\\' + server;
}
Thanks in advance, Mike
source
share