Send XML C#

Posted on 2011-04-24
Last Modified: 2012-06-27
I need to send an xml document. I got an example how to do this but it is for Apache.
How would I modify this for C#?

string gatewayURL ="http:...";
        string theXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
PostMethod post = new PostMethod(gatewayURL);
RequestEntity entity = new StringRequestEntity(theXML);
// Get HTTP client
HttpClient httpclient = new HttpClient();
// Execute request
int result = 0;
result = httpclient.executeMethod(post);
// Display status code"Response status code: " + result);
// Display response"Response body: "
catch (IOException ex)
logger.error ("Could not contact msg gateway '");
// Release current connection to the connection pool when

Question by:johnkainn
    LVL 8

    Expert Comment

    Could you explain exactly what you're trying to achieve? If you just want to send an xml response to client, the following code should make it.
    Best regards.
    string xml = SomeMethodReturningXml();
    Response.ContentType = "text/xml";

    Open in new window


    Author Comment

    Thank you. Sorry for unclear question.
    I would like to write the XML in code behind in C# and then send XML to a webservice.
    Then I would like to receive a file and store in a folder.
    I am not very familar with XML. I would appreciate your help.
    LVL 8

    Accepted Solution

    Then maybe this is not the right way to do it..
     It's easier to add a web reference to your project, and call the webservice without using xml directly, instead, use normal object notation.
    Find some examples in the following links.
    Best regards.


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now