{"id":133,"date":"2009-10-28T19:11:05","date_gmt":"2009-10-28T17:11:05","guid":{"rendered":"http:\/\/kinsey.no\/blog\/?p=133"},"modified":"2010-12-28T10:56:34","modified_gmt":"2010-12-28T08:56:34","slug":"using-wcfsvcs-automatically-generated-javascript-proxies-_without_-asp-net-ajax","status":"publish","type":"post","link":"https:\/\/kinsey.no\/blog\/index.php\/2009\/10\/28\/using-wcfsvcs-automatically-generated-javascript-proxies-_without_-asp-net-ajax\/","title":{"rendered":"Using WCF\/svc&#8217;s automatically generated javascript proxies _without_ ASP.NET AJAX"},"content":{"rendered":"<p>Most of my web based projects consist of WCF driven webservices at the backend and a javascript UI using <a href=\"http:\/\/extjs.com\" target=\"_blank\">ExtJS<\/a>, and for access to the WCF webservice I like to use its automatically generated proxies as this abstracts away the feeling of working with XMLHttpRequests, actually it abstracts it to a level where you can call the server side method &#8216;directly&#8217;, specifying only a callback function that should receive the response. These proxies are dynamically generated and will always reflect the serverside methods signature.<br \/>\n<!--more--><br \/>\nTo use the proxies all you need to do is (as long as the correct bindings are in place) access the .svc file with either &#8216;\/js&#8217; or &#8216;\/jsdebug&#8217; appended, and you will get the generated proxies.<br \/>\nBy the way, if you use any objects, either as an argument or as a return type, these will also be created as javascript &#8216;classes&#8217;, the same with any enumerations &#8211; its all wery nice.<\/p>\n<p>Using both <a href=\"http:\/\/www.asp.net\/ajax\/\" target=\"_blank\">ASP.NET AJAX<\/a> and <a href=\"http:\/\/extjs.com\" target=\"_blank\">ExtJS <\/a>on the same page does not create any serious problems (I think there might be a couple of collisions on the Date object), but it does mean that you have quite a bit of overhead.<\/p>\n<p>Removing the ASP.NET AJAX framework does not work initially as the generated proxy code needs this to work, so if we remove the ASP.NET AJAX framework, well, then we are going to need to replace it with something that caters to the proxy codes needs without the extra overhead of loading the entire ASP.NET AJAX framework. And here it is &#8211; this is the minimum of code needed to bootstrap the automatically generated proxy code, and to tie it into the ExtJs framework. If you want to use it with a different framework then it should not be a difficult task to exchange the Ext dependencies.<\/p>\n<pre class=\"brush: jscript; smart-tabs: true; tab-size: 4; title: ; notranslate\" title=\"\">\r\n\/\/ Extend Functions prototype\r\nFunction.prototype.initializeBase = function(instance, baseArguments){\r\n};\r\nFunction.prototype.registerClass = function(typeName, baseType, interfaceTypes){\r\n    if (baseType) {\r\n        for (var name in baseType.prototype) {\r\n            this.prototype[name] = baseType.prototype[name];\r\n        }\r\n    }\r\n};\r\nFunction.prototype.registerEnum = function(name, flags){\r\n};\r\n\r\n\/\/ Add Type and Type.registerNamespace\r\nvar Type = {\r\n    registerNamespace: function(ns){\r\n        var va = window;\r\n        ns = ns.split(&quot;.&quot;);\r\n        for (var i = 0, len = ns.length; i &lt; len; i++) {\r\n            va = va[ns[i]] = {};\r\n        }\r\n    }\r\n};\r\n\r\n\/\/ Create the Sys.Net.WebServiceProxy object\r\nType.registerNamespace(&quot;Sys.Net&quot;);\r\n\r\nSys.Net.WebServiceProxy = function(){\r\n    \/\/empty constructor\r\n};\r\n\r\nSys.Net.WebServiceProxy._generateTypedConstructor = function(type){\r\n    return function(properties){\r\n        if (properties) {\r\n            for (var name in properties) {\r\n                this[name] = properties[name];\r\n            }\r\n        }\r\n        this.__type = type;\r\n    };\r\n};\r\n\r\n\r\nSys.Net.WebServiceProxy.prototype._invoke = function(path, action, useGet, params, onSuccess, onFailure, userContext){\r\n    \/\/ Use Ext.Ajax to perform the xhr call\r\n    Ext.Ajax.request({\r\n        url: path + &quot;\/&quot; + action,\r\n        method: useGet ? &quot;get&quot; : &quot;post&quot;,\r\n        jsonData: params,\r\n        success: function(data){\r\n            onSuccess(Ext.decode(data.responseText).d);\r\n        },\r\n        failure: function(data){\r\n            onFailure(Ext.decode(data.responseText).d);\r\n        },\r\n        scope: userContext\r\n    });\r\n};\r\nSys.Net.WebServiceProxy.prototype.set_path = function(path){\r\n    this._path = path;\r\n};\r\nSys.Net.WebServiceProxy.prototype.get_path = function(){\r\n    return this._path;\r\n};\r\n\r\n<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Most of my web based projects consist of WCF driven webservices at the backend and a javascript UI using ExtJS, and for access to the WCF webservice I like to use its automatically generated proxies as this abstracts away the feeling of working with XMLHttpRequests, actually it abstracts it to a level where you can [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[43,23,8,44,41,40,42],"_links":{"self":[{"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/posts\/133"}],"collection":[{"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":10,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/posts\/133\/revisions\/141"}],"wp:attachment":[{"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kinsey.no\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}