我有以下(来自Tridion PowerTools),当一些JavaScript运行时,它从CoreService获取用户名.
JavaScript(安圭拉):
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);
};
Run Code Online (Sandbox Code Playgroud)
CoreService方面:(C#.svc)
[OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
public ExampleData GetUserInfo()
{
var coreService = Client.GetCoreService();
_exampleData = new ExampleData()
{
UserName = coreService.GetCurrentUser().Title
};
return _exampleData;
}
Run Code Online (Sandbox Code Playgroud)
这会发送异步调用:
PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false)
而这会分配不同的功能来处理响应:
Function.getDelegate(this, this._handleUserInfo)
但onSuccess,onFailure,context和Boolean的来源是PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false)什么?
此四参数签名与服务代码中的无参数GetUserInfo()不匹配.为什么那个订单和这四个?
该onSuccess和onFailure是分配用于处理来自WCF服务的响应回调函数.
假设这是来自PowerTools项目的代码,则会有一个自动生成的JavaScript方法,该方法充当WCF服务(此处为服务源)方法的代理方法GetUserInfo().
在那里,您实际上可以看到对CoreService的调用.这应该向您解释代理参数的映射.
onSuccess 是处理WCF服务响应的函数onFailure 是调用失败时运行的函数 context 是一个将传递回回调函数的变量,因此您可以使用它来传递内容.false 是呼叫是否同步如果您的WCF服务采用参数,则生成的代理将形成不同的签名,例如
PowerTools.Model.Services.Example.GetOtherInfo(param1, param2, onSuccess,
onFailure, context, false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
556 次 |
| 最近记录: |