gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:57:15 26 4
gpt4 key购买 nike

我有以下内容(来自 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);
};

核心服务端:(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, onFailure, context, false)
而这分配了一个不同的函数来处理响应:
Function.getDelegate(this, this._handleUserInfo)
但是 onSuccess、onFailure、context 和 Boolean 是从哪里来的: PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false) ?

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

最佳答案

onSuccessonFailure是分配用于处理来自 WCF 服务的响应的回调函数。

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

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

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

  • 如果您的 WCF 服务要接受参数,则生成的代理将形成不同的签名,例如
    PowerTools.Model.Services.Example.GetOtherInfo(param1, param2, onSuccess, 
    onFailure, context, false);

    关于tridion - 从 Anguilla JavaScript 调用 WCF Web 方法时,所有这些参数是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9385892/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com