Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8725131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:58:17+00:00 2026-06-13T07:58:17+00:00

I was given a XSD file and sample XML file, and asked to post

  • 0

I was given a XSD file and sample XML file, and asked to post the XML file to a URL.

Sample XML file

<?xml version="1.0"?>
<pingRequest>
   <elt></elt>
   ...
</pingRequest>

I’m familiar with SOAP and REST, but I have never done posting pure XML file directly. Here is what I got so far.

1) Generate C# class from XSD file

 xsd.exe Test.xsd /c

2) Serialize from C# class to XML using XmlSerializer

public string SerializeObject(object obj, Type type)
{
    string xml;
    var xs = new XmlSerializer(type);
    using (var ms = new MemoryStream())
    {
        xs.Serialize(ms, obj, null);
        ms.Position = 0;
        using (var sr = new StreamReader(memoryStream))
        {
            xml = sr.ReadToEnd();
        }
    }
    return xml;
}

OR Should I use LINQ to XML to generate XML file?

3) Post XML to URL using WebClient

var client = new WebClient();
var uri = new Uri("http://www.site.com/");
string responseXML = client.UploadString(uri, requestXML);

Am I at the right track? If not, could you please point me to a right direction? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:58:18+00:00Added an answer on June 13, 2026 at 7:58 am

    Here is my partial code so that other can use it.

    First, created two classes based on XML tags using xsd.exe Test.xsd /c (for both request and response), so that I do not have to prase the XML files manually.

    public pingResponse Send()
    {
      var pingRequest = new pingRequest
      {
        myelement = "test"
      };
    
      // Serialize pingRequest class to xml
      var serializer = new Serializer();
      string requestXml = serializer.SerializeObject(pingRequest, typeof(pingRequest));
    
      // Post xml
      var client = new WebClient(); 
      var uri = new Uri("http://www.site.com/"); 
      string responseXML = client.UploadString(uri, requestXML); 
    
      return (pingResponse)serializer.DeserializeObject(xml, typeof(Response));
    }
    
    
    public class Serializer
    {
      public string SerializeObject(object obj, Type type)
      {
        var setting = new XmlWriterSettings() {OmitXmlDeclaration = true, Indent = true};
        var xml = new StringBuilder();
        using (var writer = XmlWriter.Create(xml, setting))
        {
          var nsSerializer = new XmlSerializerNamespaces();
          nsSerializer.Add(string.Empty, string.Empty);
    
          var xmlSerializer = new XmlSerializer(type);
          xmlSerializer.Serialize(writer, obj, nsSerializer);
        }   
        return xml.ToString();
      }
    
      public object DeserializeObject(string xml, Type type)
      {
        var xs = new XmlSerializer(type);
        var stringReader = new StringReader(xml);
        var obj = xs.Deserialize(stringReader);
        stringReader.Close();
        return obj;
      }
    }
    

    Note: I do not include the PingRequest and PingResponse classes since my member variables will not be same as yours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ihave an xml file sample.xml <?xml version=1.0 standalone=yes?> <DataSchema xmlns=http://tempuri.org/DataSchema.xsd> <ManagedObject> <Label>sam</Label> <Owner>00000000-0000-0000-0000-000000000000</Owner> <ClassID>00000000-0000-0000-0000-000000000008</ClassID>
I'm trying to validate my XML files from given XSD file with the following
I have two files: A sample XML file. A .xsd file w/ schema, which
I need to validate an XML file with a given XSD file. I simply
I want to create a XML file according to a given XSD schema file.
I'm creating an xml file and have an XSD file to work against. I'm
Given the following C# code to generate an XML file: XmlDocument requestXML = new
I created the following XSD (with Eclipse): <?xml version=1.0 encoding=UTF-8?> <schema targetNamespace=http://www.example.com xmlns=http://www.w3.org/2001/XMLSchema xmlns:tns=http://www.example.com>
I need to generate a WSDL file given an XSD file. How do I
I have this code to validate an XML file against an XSD file: $file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.