【问题标题】:Where are these extra parameters coming from?这些额外的参数从何而来?
【发布时间】:2013-01-02 19:46:37
【问题描述】:

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

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

当他们引用函数客户端时,他们传递 4 个参数。我想知道这些额外参数是在哪里定义的,它们的用途等等。

这是服务器端代码:

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

是否有一些可以传递的可选参数的标准列表?记录此内容的链接?

编辑:在与同事询问后,他给我发了这个。有谁知道这是在哪里生成的以及由什么生成的?

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

【问题讨论】:

  • 您是否真的尝试过构建教程中列出的项目?我怀疑调用是一个代理调用,它需要一些委托而不是直接方法调用。

标签: ajax wcf


【解决方案1】:

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

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

【讨论】:

  • 谢谢!你知道一个详细讨论这个的网站吗?
  • 不幸的是,我没有。我只是快速谷歌搜索,但只找到了其他几个教程。没有关于代码生成器具体做什么的详细信息。我只是能够识别出使用其他 WCF 客户端类型(例如 SOAP)的行为,这些客户端类型也会生成代理类。
猜你喜欢
  • 2019-12-18
  • 1970-01-01
  • 2017-01-19
  • 2014-03-22
  • 2013-04-01
  • 1970-01-01
  • 2021-07-31
  • 1970-01-01
  • 2015-07-22
相关资源
最近更新 更多