What do all these options mean when calling the WCF web method from Anguilla JavaScript?

I have the following (from Tridion PowerTools ) that gets the username from CoreService when some kind of JavaScript is running.

JavaScript (Anguilla):

PowerTools.Popups.Example.prototype._onbtnGetUserInfoClicked = function () { var onSuccess = Function.getDelegate(this, this._handleUserInfo); var onFailure = null; var context = null; //call function PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false); }; // Delegate function "onSuccess" PowerTools.Popups.Example.prototype._handleUserInfo = function (response) { var p = this.properties; $j("#lblUserInfo").text(response.UserName); }; 

CoreService Side: (C # .svc)

 [OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)] public ExampleData GetUserInfo() { var coreService = Client.GetCoreService(); _exampleData = new ExampleData() { UserName = coreService.GetCurrentUser().Title }; return _exampleData; } 

Sends an asynchronous call:

PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false)

While this assigns another function to handle the response:

Function.getDelegate(this, this._handleUserInfo)

But where does onSuccess, onFailure, context and Boolean: PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false) ?

This four-parameter signature does not match the no-paramater GetUserInfo () in the utility code. Why is this order and these four?

+7
source share
1 answer

onSuccess and onFailure are callback functions that are assigned to handle the response from the WCF service.

Assuming this code is from a PowerTools project, there is an autogenerated JavaScript method that acts as a proxy method for the WCF service (the source of the service is here ) called GetUserInfo() .

There you can see the call to CoreService. This should explain to you the mapping of proxy settings.

  • onSuccess is a function to handle the response of a WCF service.
  • onFailure is a function executed if a call fails
  • context is a variable that will be passed back to your callback functions, so you can use it to pass information.
  • false is whether the call is synchronous or not

If your WCF service had to accept parameters, the generated proxy would form a different signature, something like

 PowerTools.Model.Services.Example.GetOtherInfo(param1, param2, onSuccess, onFailure, context, false); 
+7
source

All Articles