简体   繁体   中英

WCF Practises in Windows Phone

I have added a very basic WCF Service to my windows phone application. When hitting a button on the windows phone UI, I am calling _service.AddTwoNumbersAsync(1, 2); , which simply returns the answer in int .

I have a AddTwoNumbersCompleted event where I simply do MessageBox.Show(e.Result.ToString());

This works perfectly fine and the correct answer is returned.

My question is - in terms of best practices, is this the most standard way of calling a method in the service? Am I not calling it properly? Do I need to do OpenAsyn() for anything? Is this a safe way of calling the service?

The way you are using it right now is the right way. You have a service client, calling the asynchronous method and binding to the callback event handler. There is really not much to it than this unless you will attempt to modify client configuration of use it synchronously.

Be aware that by calling an async method you are switching thread contexts - that should be your main concern, if anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM