We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Send XML C#

johnkainn
johnkainn asked
on
Medium Priority
802 Views
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\" ?>";
<read>
<voice></voice>
<language></language>
<ip></ip>
<site></site>
<text></text>
</read>";
PostMethod post = new PostMethod(gatewayURL);
RequestEntity entity = new StringRequestEntity(theXML);
post.setRequestEntity(entity);
// Get HTTP client
HttpClient httpclient = new HttpClient();
// Execute request
try
{
int result = 0;
try
{
result = httpclient.executeMethod(post);
// Display status code
logger.info("Response status code: " + result);
// Display response
logger.info("Response body: "
post.getResponseBodyAsString());
}
catch (IOException ex)
{
logger.error ("Could not contact msg gateway '");
}
}
finally
{
// Release current connection to the connection pool when
done
post.releaseConnection();
}

    }
}
Comment
Watch Question

Hello:
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.Clear();
Response.ContentType = "text/xml";
Response.Write(xml);

Open in new window

Author

Commented:
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.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.