SIGN UP MEMBER LOGIN:    
ARTICLE

XML Web Services Type Marshaling

Posted by R. Seenivasaragavan Ramadurai Articles | Web Services in C# February 20, 2002
This article illustrates that various data types can be passed to and returned from Web Service methods.
Reader Level:

Description

This article illustrates that various data types can be passed to and returned from Web Service methods. Because the XML Web services implementation is built on top of the XML Serialization architecture, it supports more number of data types. Here I am going to show Web Service which returns String, Array, Class, integer, and Dataset.

Note: This Article Based on RC1 Version

Integer Type

//This WebMethod will take two integer Arguments and return
// result as int data type
[WebMethod]
public int Add (int A, int B)
{
return A+B;
}

String Type

//This WebMethod will take no Arguments and return
// result as string data type
[WebMethod]
public string HelloWorld()
{
return "Hello Seenivasaragavan";
}

Class Type

//This WebMethod will take no Arguments and return
// result as class data type.
[WebMethod]
public Person GetMyRecord ()
{
Person s=
new Person ();
s.Name ="S.Siddarth Sundarram";
s.age ="1.5";
s.Address ="1036 san Jacinto drive";
return s;
}

Integer Array

//This WebMethod will take no Arguments and return
// result as int Array data type
[WebMethod]
public int[] MyMarks()
{
int i;
int [] Marks = new int [5];
for (i=0;i<5;i++)
{
Marks[i]=3*20;
}
return Marks;
}

Dataset

//This WebMethod will take no Arguments and return
// result as Dataset data type
//In this WebMethod I am reading windows eventlog and //constructing a XML and writing to one file from that
//XML to Dataset
[WebMethod()]
public DataSet ReadEventLog()
{
DataSet ds =
new DataSet(); // Creating DataSet objects
EventLog aLog = new EventLog();
AppLog.Log = "Application";
//Reading only Application logs
AppLog.MachineName = "."; // Local machine
string str="<?xml version='1.0' ?>";
str=str+"<MSG>";
foreach (EventLogEntry entry in AppLog.Entries)
{
str = str +"<Msg>";
str=str + "<Type>"+entry.EntryType+"</Type>";
str =str+"<Date>"+entry.TimeWritten.ToString()+"</Date>";
str =str +"<Source>"+entry.Source+"</Source>";
str =str+"<Description>"+entry.Message.ToString()+"</Description>";
str=str+"</Msg>";
}
str=str+"</MSG>";
FileStream fs =
new FileStream("c:\\Raga.xml" , FileMode.Create, FileAccess.ReadWrite);
//Now let's put some text into the file using the StreamWriter
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(str);
sw.Flush();
sw.Close();
ds.ReadXml("c:\\raga.xml");
return ds;
}

This is Output of Windows EventLog which returns from ReadEventLog WebMethod as dataset

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor