using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using System.Text;

namespace testserialize001
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public customerinfoRpl getCustomerInfo(i2wreq i2wreq, customerinfoReq custreq)

{

// Convert custreq to a valid xmldocument, in the form of a string
String input = Serialize(custreq);

// Create a xml document for the input string, so we can get the data (nodes) we want!
XmlDocument xmlToI2w = new XmlDocument();

// Load the input string (contains XML) into the xml document
xmlToI2w.LoadXml(input);

// Create an instance of the webservice we want to call...
i2web.i2wxml.WebService calli2w = new i2web.i2wxml.WebService();

// Call the generic webservice, with the requried information)
// Put the return data into a XmlNode (as the return data from i2w is an xml document)
XmlNode x = calli2w.i2wxml(i2wreq.wscode, i2wreq.userid, i2wreq.webfunc,i2wreq.websubfunc, xmlToI2w.LastChild.InnerXml);

// Get the inner data from the xml string. (the outer is root) default i2web.
string inxml = x.FirstChild.InnerXml;

// Set object types for deserialize function
Type T = typeof(customerinfoRpl);

// Create a object to recive the result from the deserialize function
Object customer2 = Deserialize(inxml, T);

// Return the object, type casted as a customerinfoRpl
return (customerinfoRpl)customer2;
}

// Generel function for xml->Obj
public static object Deserialize(string data, Type dataType)
{
using (TextReader rd = new StringReader(data))
{
XmlSerializer sr = new XmlSerializer(dataType);
return sr.Deserialize(rd);
}
}
// Generel function for obj->xml
public static string Serialize(object item)
{
StringBuilder bld = new StringBuilder();
using (XmlWriter xmlWr = XmlWriter.Create(bld))
{
XmlSerializer sr = new XmlSerializer(item.GetType());
sr.Serialize(xmlWr, item);
return bld.ToString();
}
}

}
}