I have a problem assigning a value with the help of a WebMethod. I have a method from where I call the WebMethod:
................
svc.GetNameCompleted += GetUserName;
svc.GetNameAsync(ordercode);
string name = MyName;
................
The problem is that the third line is executed first (string name = MyName;
) and then the GetUserName()
method.
In the GetUserName()
method, I assign a value to MyName
variable, but since this is called after (string name=MyName
), the first time I execute the project, I got string name = null;
since the MyName
variable is null
.
As far as I know, you can't. All the web service calls in Silverlight are asynchronous. You cannot call an asynchronous method synchronously. You should capture the result in an asynchronous way and tell Silverlight what to do with it as soon as the method completed its execution.
I think you should write an EventHandler for your web method, in order to manage the completion of the method and handle the result.