Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Posting XML file to Web service in .NET C# and recieving response Expand / Collapse
Author
Message
Posted Tuesday, February 19, 2013 12:46 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Yesterday @ 11:42 AM
Points: 10, Visits: 159
I am posting XML file to Web services using C# , but I am getting error when I am requesting the response 'Server Error - 500 - You are not allowed to access the system . Any help will be appreciated.


protected void Page_Load(object sender, EventArgs e)
{
WebRequest req = null;
WebResponse rsp = null;
try
{
string fileName = Server.MapPath("~\\test.xml");
string uri = "http://212.170.239.71/appservices/http/FrontendService";
req = WebRequest.Create(uri);
//req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Credentials = new NetworkCredential("myusername", "mypassword");
req.Method = "POST"; // Post method
req.ContentType = "text/xml"; // content type
// Wrap the request stream with a text-based writer
StreamWriter writer = new StreamWriter(req.GetRequestStream());
// Write the XML text into the stream
writer.WriteLine(this.GetTextFromXMLFile(fileName));
writer.Close();
// Send the data to the webserver
rsp = req.GetResponse(); //I am getting error over here
StreamReader sr = new StreamReader(rsp.GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
Response.Write(result);

}
catch (WebException webEx)
{
Response.Write(webEx.Message.ToString());
Response.Write(webEx.StackTrace.ToString());
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
Response.Write(ex.StackTrace.ToString());
}
finally
{
if (req != null) req.GetRequestStream().Close();
if (rsp != null) rsp.GetResponseStream().Close();
}
}
//Function to read xml data from local system
/// <summary>
/// Read XML data from file
/// </summary>
/// <param name="file"></param>
/// <returns>returns file content in XML string format</returns>
private string GetTextFromXMLFile(string file)
{
StreamReader reader = new StreamReader(file);
string ret = reader.ReadToEnd();
reader.Close();
return ret;
}
Post #1421810
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse