0

私はここでこのMSDNの記事を見ています:http://msdn.microsoft.com/en-us/library/bb924552.aspx

コードビハインドファイルでは、quantityという単一のintパラメーターを受け取るCostOfSandwichesという関数を作成します。

関数クライアント側を参照する場合、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()); 
    } 
4

1 に答える 1

1

同僚から送られてきたコードは、「CostOfSandwiches.svc」にサービス参照を追加すると、Visual Studio のツールによって生成されます。

VS がクライアント プロキシを生成すると、実際のサービス呼び出しがラップされ、サービスの呼び出し方法と完了時の反応方法を制御できるようになります。

于 2013-01-02T20:28:53.240 に答える