2013-01-02 53 views
0

我期待這個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()); 
    } 
+0

您是否真的嘗試過在tuturial中制定項目?我懷疑這個調​​用是一個代理調用,它需要一些代理而不是直接的方法調用。 –

回答

1

你的同事發送給您的代碼是由Visual Studio的工具,當您添加服務參考「CostOfSandwiches.svc」產生。

當VS生成您的客戶端代理時,它將爲您封裝實際的服務調用,從而允許您控制服務的調用方式以及完成時的響應方式。

+0

謝謝!你知道一個網站詳細談論這個嗎? – Legion

+0

不幸的是,我沒有。我剛剛進行了Google搜索,但只找到了其他一些教程。沒有關於代碼生成器具體做什麼的細節。我只是能夠識別使用其他WCF客戶端類型(例如SOAP)的行爲,這些客戶端類型也生成代理類。 –