Hello, all!
We're finally implementing messaging rules on our still-mostly-SOAP site. We are using an old version of the REST C# SDK. In our version the RestClient.Get<T> method is not marked as async.Is this method safe to use in a synchronous method? Do we need to update our REST C# SDK (in which the same method is async)? If so can we safely use the same method in a synchronous method (like this: stackoverflow.com/.../calling-async-methods-from-non-async-code)?
Thanks!
Monica
Oregon Shakespeare Festival
First and most important: You should always be using the sdk version that matches your REST service version. Calling a newer version of the service from an old version of the SDK can cause all sorts of version and contract mismatch issues.
As for async vs synchronous. There is no issue calling an async method in a synchronous way. The method I prefer personally is:
SomeResponseType response = null;var t = Task.Run(async () => {response = await GetStuff()...});t.Wait();...use response;
There are several valid variations on this, but be careful with GetAwaiter() and GetResult(). The thread you linked has several good points about deadlocks and exception hiding that are worth noting and understanding.
Hope this helps.
Dave
Thank you for your response, Dave! This is all good news for what we're trying to do.
Best,