Answered by:
How to create async interface in WCF service to use with a Silverlight client?

Question
-
User-493262165 posted
I am having difficulty with transforming my synchronous WCF Service design to an asynchronous one that my Silverlight client can use. Here's an import of my IMyWCFService.cs file:
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace MyWCFService { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IMyWCFService" in both code and config file together. [ServiceContract] public interface IMyWCFService { [OperationContract(AsyncPattern = true)] //string SayHello(String name); IAsyncResult BeginSayHello(String name, AsyncCallback cb, Object state); string EndSayHello(IAsyncResult result); [OperationContract(AsyncPattern = true)] //int ComputeY(int m, int x, int b); IAsyncResult BeginComputeY(int m, int x, int b, AsyncCallback cb, Object state); string EndBeginComputeY(IAsyncResult result); } }
And here is the code in my MyWCFService.svc.cs file:
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace MyWCFService { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MyWCFService" in code, svc and config file together. public class MyWCFService : IMyWCFService { public string SayHello(String name) { return "Hello " + name; } public IAsyncResult BeginSayhello(String name, AsyncCallback cb, Object state) { Console.WriteLine("BeginSayHello called with: " + name); return new CompletedAsyncResult<string>(name); } public int ComputeY(int m, int x, int b) { return (m * x) + b; } } }
These are the error messages that I am getting right now, and I don' know how to get around them:
c:\users\a0171964\documents\visual studio 2010\Projects\MyWCFService\MyWCFService\MyWCFService.svc.cs(11,18): error CS0535: 'MyWCFService.MyWCFService' does not implement interface member 'MyWCFService.IMyWCFService.BeginSayHello(string, System.AsyncCallback, object)' c:\users\a0171964\documents\visual studio 2010\Projects\MyWCFService\MyWCFService\IMyWCFService.cs(16,22): (Related location) c:\users\a0171964\documents\visual studio 2010\Projects\MyWCFService\MyWCFService\MyWCFService.svc.cs(11,18): error CS0535: 'MyWCFService.MyWCFService' does not implement interface member 'MyWCFService.IMyWCFService.EndSayHello(System.IAsyncResult)' c:\users\a0171964\documents\visual studio 2010\Projects\MyWCFService\MyWCFService\IMyWCFService.cs(18,16): (Related location) c:\users\a0171964\documents\visual studio 2010\Projects\MyWCFService\MyWCFService\MyWCFService.svc.cs(11,18): error CS0535: 'MyWCFService.MyWCFService' does not implement interface member 'MyWCFService.IMyWCFService.BeginComputeY(int, int, int, System.AsyncCallback, object)' c:\users\a0171964\documents\visual studio 2010\Projects\MyWCFService\MyWCFService\IMyWCFService.cs(22,22): (Related location) c:\users\a0171964\documents\visual studio 2010\Projects\MyWCFService\MyWCFService\MyWCFService.svc.cs(11,18): error CS0535: 'MyWCFService.MyWCFService' does not implement interface member 'MyWCFService.IMyWCFService.EndBeginComputeY(System.IAsyncResult)' c:\users\a0171964\documents\visual studio 2010\Projects\MyWCFService\MyWCFService\IMyWCFService.cs(24,16): (Related location) Compile complete -- 4 errors, 0 warnings
Can anyone please shed some light on what I am doing wrong at this point? I'm at a standstill right now -- I can't find any examples on the net to help me get around these errors.
-Bob
Monday, February 18, 2013 2:59 PM
Answers
-
User-1000095884 posted
Hi,
It seems ok with the code you provided above, but below is a blog which include a complete sample code that you can refer.
#How to: Implement a WCF Asynchronous Service Operation with Task<T>
<!--EndFragment-->http://blogs.msdn.com/b/rjacobs/archive/2011/06/30/how-to-implement-a-wcf-asynchronous-service-operation-with-task-lt-t-gt.aspx
Best Regards.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 21, 2013 1:22 AM
All replies
-
User2118885047 posted
Here's the sample application from msdn:
Monday, February 18, 2013 3:12 PM -
User-493262165 posted
I've already been to this site and have been reviewing it. I'm still having issues with how to connect the Beginxxxxxxx and Endxxxxxxxx code segments together. Being new to using WCF and Silverlight, I'm needing more help/insight into this.
Thanks,
Bob
Tuesday, February 19, 2013 10:04 AM -
User-1000095884 posted
Hi,
It seems ok with the code you provided above, but below is a blog which include a complete sample code that you can refer.
#How to: Implement a WCF Asynchronous Service Operation with Task<T>
<!--EndFragment-->http://blogs.msdn.com/b/rjacobs/archive/2011/06/30/how-to-implement-a-wcf-asynchronous-service-operation-with-task-lt-t-gt.aspx
Best Regards.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, February 21, 2013 1:22 AM