Need help using Smart Web Reference

Topics: CAB & Smart Client Software Factory
Apr 10, 2007 at 12:01 AM
Hello, I am relatively new to SCSF/CAB and think I am missing something fundamental when it comes to using a smart web reference. Has anyone seen any simple examples that calls a webservice asynch (using the recipe)? I have created a web service that potentially will take 30+ seconds to return. Seems like a good candidate for calling asynch. Here is the code that I am using: (partly copies from Appraisal Workbench)

In my controller:
       private void AddServices() 
            MyWebService myService = new MyWebService();  
            //myService.Credentials = new NetworkCredential("username", "password");
            MyWebServiceProxy myServiceProxy = new MyWebServiceProxy(myService);  

In my Presenter:
        public MyViewPresenter([ServiceDependency] IMyWebServiceProxy myProxy)
            _myProxy = myProxy;
       public MyResults[] GetMyResults()
           // How do I call my web service asynchronously here?
           // method signature is (int timeout, CommandWithCallback<IMyWebService, MyResults[]>.CallbackType callback)
The recipe created an appropriate command (GetResultsCommand) for my method, but I am still trying to figure out how to call it. Any help is appreciated.


Apr 10, 2007 at 4:28 AM
I knew I would figure this out after requesting help. The problem was obvious, I must have been sleepy after lunch. ;)

In my presenter, I added a delegate:

        public delegate void GetResultsCallback(bool success, MyResults[] stats);

Then replaced the method call as follows:

        public void GetMyResults()
            ResultsCommand.CallbackType cmd = new ResultsCommand.CallbackType(new GetResultsCallback(myCallBack));
            _myProxy.GetResults(30, cmd);
        public void myCallBack(bool success, MyResults[] stats)
        { // Call my view here and give it the results!

So my misunderstaning really had nothing to do with SCSF/CAB, just delegates.
Apr 11, 2007 at 4:08 PM
Hi Tom I having a problem with this I have done very much the same as you however I cannot get the "myCallBack" to ever fire off, I think it is in the way I am creating the cmd instance :
getMyNewTasksCommand.CallbackType cmd = new Myproject.DeliveryPlatform.Infrastructure.Interface.Commands.CommandWithCallback<IWPSProxyService, TaskDTO[]>.CallbackType(new GetTasksDelegate(myCallBack))
and then
calling the proxy
wpsproxy.getMyNewTasksAsync(20, cmd)
any thing you can spot thats not right here ?

thanx nitesh
Apr 12, 2007 at 5:21 PM
Looks like your cmd is created slightly different than mine, but I assume it compiles. I believe the timeout is in milliseconds btw, after I got the callback working, I noticed it failed half the time until I changed the timeout. However, the timeout value wouldn't prevent your callback from working, just the the success parameter would be false.

Did you use the Smart client guidance to add a smart web reference? If so, that should have created a command with your method's name like GetMyNewTasksCommand.


Apr 13, 2007 at 9:13 AM
Hi Tom,to answer your questions yes i used the smart web reference and yes it compiles, it created the method getMyNewTasksCommand in my case and this is what i used.
thanx for your comment