Because the Implementation of Web services is based on the XML serialization structure, it supports a considerable number of data types. When the SOAP protocol is used, both value-based and reference-based parameters are supported. The value can be sent in two directions according to the reference parameter: up to the server and down to the client. When you pass input parameters to the XML Web Service using HTTP-GET and HTTP-POST, only a limited set of data types are supported and they must be value-based parameters. The following example demonstrates encapsulation of several data types.
Using System;
Using System. collections;
Using System. componentmodel;
Using System. Data;
Using System. diagnostics;
Using System. Web;
Using System. Web. Services;
Using System. xml;
Using System. Data. sqlclient;
/// <Summary>
/// Summary of datatypews
/// </Summary>
[WebService (namespace = " Http://tempuri.org/ " )]
[Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
Public Class Datatypews: system. Web. Services. WebService
{
PublicDatatypews ()
{
//If you use the designed components, uncomment the following lines:
//Initializecomponent ();
}
[webmethod]
Public string helloworld ()
{< br> return " Hello World " ;
}
[Webmethod]
Public StringHello (person P)
{
Return "Hello,"+P. Name;
}
[Webmethod]
Public Int [] Getintarray ()
{
Int [] = New Int [ 5 ];
For ( Int I = 0 ; I < 5 ; I ++ )
A [I] = I * 10 ;
Return A;
}
[Webmethod]
PublicMode getmode ()
{
ReturnMode. off;
}
[webmethod]
Public order getorder ()
{< br> order myorder = New Order ();
myorder. price = 34.5 ;< br> myorder. orderid = 323232 ;< br> return myorder;
}
[Webmethod]
PublicOrder [] getorders ()
{
Order [] myorder=NewOrder [2];
Myorder [ 0 ] = New Order ();
Myorder [ 0 ]. Price = 34.5 ;
Myorder [ 0 ]. Orderid = 323232 ;
Myorder [ 1 ] = New Order ();
Myorder [ 1 ]. Price = 99.9 ;
Myorder [ 1 ]. Orderid = 646465 ;
Return Myorder;
}
[webmethod]
Public dataset getdataset ()
{< br> sqlconnection myconn = New sqlconnection ();
myconn. connectionstring = " Data Source = .; initial catalog = databasename; uid = sa; Pwd = sa " ;
sqlcommand mycmd = New sqlcommand ();
mycmd. connection = myconn;
mycmd. commandtype = commandtype. text;
mycmd. commandtext = " select * from employee " ;
sqldataadapter adapter = New sqldataadapter ();
adapter. selectcommand = mycmd;
// adapter. missingschemaaction = missingschemaaction. addwithkey;
dataset DS = New dataset ();
adapter. fill (DS, " employee " );
ReturnDS;
}
[Webmethod]
Public Xmlelement getxmlnode ()
{
Xmldocument Doc = New Xmldocument ();
Xmlelement node;
Node = Doc. createelement ( " Hello " );
Node. innerxml = " Xiaohua " ;
Return Node;
}
Public Enum Mode
{
On = 1 ,
Off = 0
}
Public Struct Order
{
Public Int Orderid;
Public Double Price;
}
Public Class Person
{
Private String Name;
Public String Name
{
Get
{
Return Name;
}
Set
{
Name = Value;
}
}
}
}