Client Class ServiceProxy

The ServiceProxy class lets you call Microsoft ASP.NET AJAX based WCF or ASMX JSON services. It handles JSON serialization and deserialization as well as URL and parameter fixups for data passed.

The key feature of this class is the invoke method which is used to invoke a server side method and call the specified callback handler with the result.

Server method Interface signature (WCF):

StockQuote GetStockQuote(string symbol);

JavaScript client code to call it.

// Create a static instance (global so it can be reused)
var serviceUrl = "JsonStockService.svc/"; // specify service 'base' url
var proxy = new serviceProxy(serviceUrl);

function GetStockQuote()
    var symbol = $("#txtSymbol").val();            
    if (!symbol)
        showStatus("Please provide a symbol value.",5000);
    // pass single symbol parameter
        function (result)  // returns a quote object
            if (!result)
                showStatus("Invalid Stock Symbol");
            $("#StockName").text( result.Company + " (" + result.Symbol + ")" ) ;
            // additional ui assignments
        function(error) { alert(error.message); },

Class Members



Calls a service method by specifying a method name, an array of parameters and a callback and error handler method.

o.JsonService.invoke(method, params, callback, errorCallback, isBare)


If true the request is set up for calling a WCF service and performs special date encoding when creating JSON. Required only for WCF services, not for ASMX services.


The url to the WCF or ASMX JSON service to be called. Can also be set via the constructor. This value needs to be set prior to calling invoke().


The timeout for the the xhr request. Default is 20,000 milliseconds.

© West Wind Technologies, 1996-2024 • Updated: 02/27/16
Comment or report problem with topic