这些额外的参数从何而来? [英] Where are these extra parameters coming from?

查看:59
本文介绍了这些额外的参数从何而来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里查看此MSDN文章: http://msdn.microsoft.com/en-us/library/bb924552.aspx

I'm looking at this MSDN article here: http://msdn.microsoft.com/en-us/library/bb924552.aspx

在文件背后的代码中,他们创建了一个称为CostOfSandwiches的函数,该函数接受一个称为数量的单个int参数.

In the code behind file they create a function called CostOfSandwiches that takes a single int parameter called quantity.

当它们引用功能客户端时,它们传递4个参数.我想知道那些额外的参数在哪里定义,它们的用途,等等.

When they reference the function client side they pass 4 parameters. I was wondering where those extra parameters are defined, what they're used for, etc.

这是服务器端代码:

public class CostService
{
    [OperationContract]
    public double CostOfSandwiches(int quantity)
    {
        return 1.25 * quantity;
    }

// Add more operations here and mark them with [OperationContract]
}

这是客户端呼叫:

function Button1_onclick() {
   var service = new SandwichServices.CostService();
   service.CostOfSandwiches(3, onSuccess, null, null);
   }

function onSuccess(result){
   alert(result);
   }

是否有一些可以传递的可选参数的标准列表?

Is there some standard list of optional parameters that can be passed? A link to where this is documented?

向同事询问后,他将此寄给了我.有人知道这是在哪里生成的,是什么生成的吗?

After inquiring with a colleague he sent me this. Anyone know where this is being generated and by what?

 function Sys$Net$WebServiceProxy$_invoke(servicePath, methodName, useGet, params, onSuccess, onFailure, userContext) { 
        /// <summary locid="M:J#Sys.Net.WebServiceProxy._invoke" /> 
        /// <param name="servicePath" type="String"></param> 
        /// <param name="methodName" type="String"></param> 
        /// <param name="useGet" type="Boolean"></param> 
        /// <param name="params"></param> 
        /// <param name="onSuccess" type="Function" mayBeNull="true" optional="true"></param> 
        /// <param name="onFailure" type="Function" mayBeNull="true" optional="true"></param> 
        /// <param name="userContext" mayBeNull="true" optional="true"></param> 
        /// <returns type="Sys.Net.WebRequest" mayBeNull="true"></returns> 
        var e = Function._validateParams(arguments, [ 
            {name: "servicePath", type: String}, 
            {name: "methodName", type: String}, 
            {name: "useGet", type: Boolean}, 
            {name: "params"}, 
            {name: "onSuccess", type: Function, mayBeNull: true, optional: true}, 
            {name: "onFailure", type: Function, mayBeNull: true, optional: true}, 
            {name: "userContext", mayBeNull: true, optional: true} 
        ]); 
        if (e) throw e; 
        onSuccess = onSuccess || this.get_defaultSucceededCallback(); 
        onFailure = onFailure || this.get_defaultFailedCallback(); 
        if (userContext === null || typeof userContext === 'undefined') userContext = this.get_defaultUserContext(); 
        return Sys.Net.WebServiceProxy.invoke(servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, this.get_timeout(), this.get_enableJsonp(), this.get_jsonpCallbackParameter()); 
    } 

推荐答案

将服务引用添加到"CostOfSandwiches.svc"时,Visual Studio的工具会生成同事发送给您的代码.

The code your colleague sent you is generated by Visual Studio's tools when you add the service reference to the "CostOfSandwiches.svc".

当VS生成您的客户端代理时,它会为您包装实际的服务调用,使您可以控制服务的调用方式以及服务完成后的反应.

When VS generates your client proxy it wraps the actual service call for you allowing you to control how the service is called and how to react when it's done.

这篇关于这些额外的参数从何而来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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