tridion – 从Anguilla JavaScript调用WCF Web方法时,所有这些参数是什么意思?

我有以下(从 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);
};

CoreService方面:(C#.svc)

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

这会发送异步调用

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

而这会分配不同的功能来处理响应:

Function.getDelegate(this,this._handleUserInfo)

但onSuccess,context和Boolean来自哪里:PowerTools.Model.Services.Example.GetUserInfo(onSuccess,false)?

此四参数签名与服务代码中的无参数GetUserInfo()不匹配.为什么那个订单和这四个?

解决方法

onSuccess和onFailure是为处理来自WCF服务的响应而分配的回调函数.

假设这是来自PowerTools项目的代码,则有一个自动生成的JavaScript方法,它充当WCF服务(服务源为here)的代理方法,称为GetUserInfo().

在那里你实际上可以看到对CoreService的调用.这应该向您解释代理参数的映射.

> onSuccess是处理WCF服务响应的函数
> onFailure是调用失败时运行的函数
> context是一个变量,它将被传递回你的回调函数,因此你可以使用它来传递信息.
> false是呼叫是否同步

如果您的WCF服务要获取参数,则生成的代理将形成不同的签名,例如

PowerTools.Model.Services.Example.GetotherInfo(param1,param2,onSuccess,false);

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...