ASP. NET: the WebService supports data-type instances.

Source: Internet
Author: User

 

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;
}
}
}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.