Click here to Skip to main content
14,830,769 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello ,

I read some articles on web about how to consume a REST function. Now I am trying to create a function that will consume xml from webrequest/response.

I know how to consume such a function but don't know how to create one.
Please tell me how to create such a function

I want to send xml in webrequest from client. I need to create a function that will consume this xml from client at server. Please help ..
Posted
Comments
   
Nearly all in ASP.NET is about "consumption" of HTTP request/response data. Could you please explain the problem in detail? Start with explanation of the ultimate goals. Why XML, what's the purpose of it? And so on...
—SA
Aakash Sharma 12-Mar-15 2:49am
   
I am creating a RESTFULL service. Client will upload records (millions of rows) consuming this service. I am trying to create a function that will consume xml that client will send in a stream.

1 solution

You can create webservice(.asmx) like this one


C#
/// <summary>
/// Summary description for GetDataWebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class GetDataWebService : System.Web.Services.WebService
{

    BooksDBEntities db = new BooksDBEntities();


    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    public List<studentserialized> GetAllStudentData()
    {
        List<student> lststu = new List<student>();
        lststu = db.Students.ToList();
        List<studentserialized> lstss = new List<studentserialized>();
        foreach (Student sss in lststu)
        {
            StudentSerialized ss = new StudentSerialized();

            ss.ID = sss.ID;
            ss.Name = sss.Name;
            ss.Roll = sss.Roll;

            lstss.Add(ss);
        }

        return lstss;

    }

  public  class StudentSerialized
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Roll { get; set; }


    }


}

This function(GetAllStudentData)  will return an XML.

XML
<arrayofstudentserialized xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
  <studentserialized>
    <id>1</id>
    <name>Anis</name>
    <roll>0718004</roll>
  </studentserialized>
  <studentserialized>
    <id>2</id>
    <name>Toma</name>
    <roll>0718040</roll>
  </studentserialized>
  <studentserialized>
    <id>3</id>
    <name>Bachchu</name>
    <roll>0717007</roll>
  </studentserialized>
</arrayofstudentserialized>
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900