Link to home
Start Free TrialLog in
Avatar of johnkainn
johnkainn

asked on

Send XML C#

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();
}

    }
}
Avatar of cubaman_24
cubaman_24
Flag of Spain image

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

Avatar of johnkainn
johnkainn

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of cubaman_24
cubaman_24
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial