 
    Executing multi-valued web service calls from javascript
Monday, October 31, 2005
I'm currently working hard on a web based business system for a theatre agency here in Denmark. Client-side business logic communicates through web service calls with server-side business logic.
I'm using the web service proxies that Matthias Hertels AJAX Engine generates,
but I was unable to use ajax.Start to execute multi-valued calls.
Maybe I overlooked something? :) Anyway, I came up with a fix for it...
This an example of a multi-valued call:
  ...
  var Add = {
    delay: 200,
    prepare: function() { return [34, 23]; },
    call: proxies.AddService.Add,
    finish: function (p) {
      alert("Sum: " + p);
    },
    onException: proxies.alertException
  };
  ajax.Start(Add);
  ...
 
I changed some lines in Ajax.js. After this:
      ...      
      // start the call
      ca.call.func = ajax.Finsh;
      ca.call.onException = ajax.Exception;
I added this:
      // multi-valued call (new)
      if ((typeof(data)=="object") && (data!=null) && data.length) {
        ca.args = new Object();
        var aArg = new Array();
        for (var i = 0; i<data.length; i++) {
          ca.args["a" + i] = data[i];
          aArg[aArg.length] = "a" + i;
        }
        with (ca.args) {
          eval("ca.call(" + aArg.join(",") + ")");
        }
      }
      // single-valued call
      else { 
        ca.call(data);
      }      
      ...
And it worked. I hope you can use this.



2 Comments:
why not use your own OutPost for AJAX enviroment?
When will you release new version of OutPost? And new example for starter kit?
Thanks.
KeithPRC@gmail.com
OutPost is intended for WebForms, not for pure business logic. So instead of adding a hidden WebForm on the page and using OutPost to call the server through post backs on the web form, I think it is more appropiate to call the server through a web service.
At the moment I am very busy in my company, so I hope to have a new release ready at the end of this month.
I am not sure that OutPost will ever support Forms Authentication, but one should be able to use it anyway, just not on the login web form. I have already spent many nights trying to solve that...
Post a Comment
<< Home