Samstag, Juli 30, 2005

Extensions to the proxy generator

With Version 2.0 there is now more support for different datatypes.

Simple data types

Up to now only those methods where supported that where converting of the parameters and result values was not necessary. This applies to strings and numbers.

Now the data types defined on the server and the WSDL are passed to the client so that the data types can be converted using JavaScript at runtime.

In the generated proxy code, the listing of the names of the parameters is now extended by an optional specification of the data type. Without this the values are treated as strings.

proxies.CalcService.AddDouble.params = ["number1:float","number2:float"];
proxies.CalcService.AddDouble.rtype = ["AddDoubleResult:float"];

In the HTML object model, the JavaScript data types are not well supported. The values that is displayed inside an input field is always a string, even if it’s containing only digits. For this all the parameters when calling the proxy are also accepted as JavaScript strings and converted if possible to the right types.

XML data

Passing XML documents was implemented to make it possible to pass complex data. In the browser clients the XMLDocument Object from Microsoft or Firefox and on the server the XmlDocument class can be used.

A Method has to be is declared in C# like this:

[WebMethod()]
public XmlDocument Calc(XmlDocument xDoc) {
...
return (xDoc);
} // Calc

The proxy functions also accept the XML document as a string type. In this case, the contents of the passed string is passed directly to the server any must for this reason contain a valid XML document without the declarations any without any “XML processing Instructions" <? ... ?>.

With this data type it is possible to pass complex data from a HTML form directly to the server an there is no need to define a method with many parameters. If the form is extended with new fields it will not be necessary to give a new signature to the WebService.

The disadvantage of this approach is that the content of the XML document cannot be validated by the WebService infrastructure because there is no schema for this part of the conversation available.

Supported Datatypes
XML data type Alias in the proxy JavaScript data taype
string string / null String
int, unsignedInt,
short, unsignedShort,
unsignedLong,s:long
int Number, (parseInt)
double, float float Number, (parseFloat)
dateTime' date Date
boolean bool Boolean
In Mozilla / Firefox:
XMLDocument
Im Internet Explorer:
ActiveXObject("Microsoft.XMLDOM")
ActiveXObject("MSXML2.DOMDocument")
x System.Xml.XmlDocument

Keine Kommentare: