Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have a XML request document which I am Posting to the WebService.

I have my project uploaded on my web server. The webservice provider has allowed access to my web server IP only.

But I am getting error when I am requesting the response 'Server Error - 500 - You are not allowed to access the system - //here it is showing my client machine's IP from which I am accessing the page//

The code is given below.

Please help.

C#
protected void Page_Load(object sender, EventArgs e)
    {
        WebRequest req = null;
        WebResponse rsp = null;
        try
        {
            string fileName = Server.MapPath("~\\HotelValuedAvailRQ.xml");
            string uri = "http://212.170.239.71/appservices/http/FrontendService";
            req = WebRequest.Create(uri);
            //req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
            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;
  }
Posted

Obviously your server is NOT configured to give you access. No change to your code will change a message that is about your rights to access the server. If you doubt this, write a service that passes an int, and see what happens.
 
Share this answer
 
Comments
tarik shaikh 21-Jul-12 5:55am    
Actually the Web service provider has given access to my web server's IP.

So how can I post the XML with my web server's IP.
Christian Graus 21-Jul-12 6:01am    
Your error message says otherwise.
C#
req.ContentType = "text/xml"; // content type

req.Credentials = CredentialCache.DefaultNetworkCredentials;
 
Share this answer
 
rsp = (HttpWebResponse) req.GetResponse();

This should work!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900