从 Anguilla JavaScript 调用 WCF Web 方法时,所有这些参数是什么意思? [英] What do all these parameters when calling a WCF web method from Anguilla JavaScript mean?

查看:15
本文介绍了从 Anguilla JavaScript 调用 WCF Web 方法时,所有这些参数是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容(来自 Tridion PowerTools),其中当某些 JavaScript 运行时,从 CoreService 获取用户名.

I have the following (from Tridion PowerTools), which gets a user name from the CoreService when some JavaScript runs.

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;
}

这会发送一个异步调用:

This sends an asynchronous call:

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

而这分配了一个不同的函数来处理响应:

Whereas this assigns a different function to handle the response:

Function.getDelegate(this, this._handleUserInfo)

但是 onSuccess、onFailure、context 和布尔值从何而来:PowerTools.Model.Services.Example.GetUserInfo(onSuccess, onFailure, context, false)?

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

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

This four-parameter signature doesn't match the no-paramater GetUserInfo() in the service code. Why that order and these four?

推荐答案

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

The onSuccess and onFailure are the callback functions that are assigned for handling the response from the WCF service.

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

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

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

In there you can actually see the call to the CoreService. That should explain to you the mapping of the proxy parameters.

  1. onSuccess 是处理WCF服务响应的函数
  2. onFailure 是调用失败时运行的函数
  3. context 是一个将传回回调函数的变量,因此您可以使用它来传递信息.
  4. false 是调用是否同步
  1. onSuccess is the function to process the response of the WCF service
  2. onFailure is the function to run if the call fails
  3. context is a variable that will be passed back into your callback functions, so you can use it to pass things around.
  4. false is whether the call is synchronous or not

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

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

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

这篇关于从 Anguilla JavaScript 调用 WCF Web 方法时,所有这些参数是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆