Monday, April 20, 2009

Wrecked Acft For Sale

Dojo + WCF [2nd Part]

In the preceding

ticket, I had proposed to invoke a WCF service using the XmlHttpRequest sauce dojo (

xhrGet

and

xhrPost ). Although this approach is much faster and more "elegant" than when you have to write or even what kind of js code (with support for browser browsers ... etc), there is an even simpler method.

Well, let us return briefly to the published web services as well as of

ASMX

wsdl. The major advantage I see in the wsdl is that it automatically generates a proxy that will connect with the target web service. Moreover, thanks to this description that Visual Studio generates the proxy class when adding a web reference in your solution. The idea behind the classes in the namespace dojox.rpc is having this same behavior in JavaScript, that is to say, the ability to query a service to know its characteristics and automatically generate a proxy JavaScript simplifying its use.

Excellent you say, we already have the wsdl ... arf that is the bottom hurt, the

xml

(and a special definition wsdl) has never been the simplest format and faster to handle JavaScript. By cons, as you already know the json format is fetish web. So from a definition in accordance json formalism named smd (for Simple Method Description) Framework dojo that will allow you to generate JavaScript proxy that corresponds to your web service. Although

truce discussion adapt our previous example to adapt this technique has proxy generation. Create the service definition:

{"transport": "POST",

"envelope": "URL",

"Target": "http://localhost/WCFDojoRpc/ClockService.svc/" "services" { "GetTime": { "transport": "GET", "target": "GetTime"

"parameters": []

}}}

We find easily at address information and method of service available. For more details, I'll let you see
 working group that is interested in SMD format. 


's modify our script a little:


\u0026lt;! DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Transitional / / EN" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
\u0026lt;html xmlns="http://www.w3.org/1999/xhtml">
\u0026lt; ; head>
\u0026lt;title> Dojo & WCF \u0026lt;/ title>

\u0026lt;script src = "http://ajax.googleapis.com/ajax/libs/dojo/1.3.0/dojo/dojo.xd. js "type =" text / javascript "> \u0026lt;/ script>

\u0026lt;script type="text/javascript">
dojo.require ('dojo.parser');

dojo.require (" dojox. rpc.Service "); was clock proxy

dojo.addOnLoad(

function() {
                 clockProxy = new dojox.rpc.Service("definition.json"); 
GetTime();
}
);

function GetTime() {
clockProxy.GetTime()
.addCallback(
function(data) {
dojo.byId('ServerTime').innerHTML = data.d;
}
)
.addErrback(
function(data) {
alert(data);
}
);


} \u0026lt;/ script>
\u0026lt;/ head>
\u0026lt;body>
\u0026lt;input type = "button" value = "Time?" onclick = "getTime ();" /> \u0026lt;div
id="ServerTime"> \u0026lt;/ div>
\u0026lt;/ body>
\u0026lt;/ html>



As you can see we mainly removed using xhrPost, we replaced by a new single line dojox.rpc.Service ("definition.json") that generates the JavaScript proxy automatically from the definition in json.

Obviously the WCF service is identical to that presented in the first part of this article.

I withdrew two partial conclusions from the use of SMD:

Certainly the possibility of describing a service then facilitates the life of the developer side js.

It is a shame to use anything other than the wsdl that is generated for us, especially when you're a developer.. NET



The best would be to have a description smd generated automatically with each change of our WCF service and it is integrated into the WCF pipeline. It what I propose to show you in the third part of this article.

0 comments:

Post a Comment