During the development of using Silverlight to call WCF, an error is encountered today.
Because Silverlight only supports asynchronous WCF calls, the code is generally like this:
Var myServiceClient = new MyServiceClient ();
MyServiceClient. GetSomeDataCompleted = (sender, args) =>
{
HtmlPage. Window. Alert ("completed .");
};
MyServiceClient. GetSomeDataAsync ();
There is no problem with this writing.
However, some friends may define the client proxy object of myServiceClient as a class field to improve code sharing so that it can be shared in multiple calls. As mentioned in this tutorial:
"This step is complicated. Here we will discuss it in a little bit. To call the WCF Service, define global variables first.
AcademeServiceClient academeSClient ;"
What's the problem with this?
Assuming that the above Code is defined in the click event handler function of a button, the GetSomeDataCompleted event handler will be registered every time you click the button. Finally, you will find that the callback function is executed multiple times after clicking the button.
Therefore, do not share the client proxy. It is better to create one before each call.
This error is reported today.