Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
Hello all,

Im trying to make a web service which accepts xml,writes to the db and then returns a message. Everything goes well on my machine. When i publish it to a remote server,with real IP,when i call the service its returns "The remote server returned an error: (400) Bad Request."
What might be the problem?

Maby i should edit my web.config??

Thanks in advance
Posted
Comments
rajkumar sharma 12-Jun-14 7:01am    
Any one Helep Me I am using contractcontact.com api Problam is that whenever I select 30 records it works properlly but select 35 record then get
The remote server returned an error: (400) Bad Request
my code is following

byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/atom+xml";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream;
try
{
dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
}
catch (WebException exWrite)
{
throw exWrite;
}
catch (Exception genException)
{
throw genException;
}
// Get the response.
WebResponse response=null ;
try
{
response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
}
catch (WebException exResponse)
{
throw exResponse;
}
StreamReader reader;
try
{
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();

// Open the stream using a StreamReader for easy access.
reader = new StreamReader(dataStream);
// Read the content.
}
catch (WebException exWrite)
{
throw exWrite;
}
catch (Exception genException)
{
throw genException;
}
string responseFromServer = reader.ReadToEnd();
// Display the content.
Response.Write(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
_msg.erorrMsg = "mail has been successfully sent";
_msg.erorrType = "1";

}
catch
{ _msg.erorrMsg = "Sorry! unable to send mail.";
_msg.erorrType = "2";

}

1 solution

You can either set the maximum size of your data which can be received:
http://stackoverflow.com/questions/5236132/wcf-error-400-bad-request-when-post-some-data[^]

Or you can change the transfer method:
http://stackoverflow.com/questions/2456301/wcf-the-remote-server-returned-an-error-400-bad-request[^]

Maybe this (WCF Service returns (400) Bad Request)[^] can give you some inputs.

Let me know if I was able to help you.


cheers,
Marco Bertschi
 
Share this answer
 
Comments
IviKAZAZI 6-Mar-13 4:58am    
the problem was the max side of data allowed :( thnx for the solution
Marco Bertschi 6-Mar-13 13:27pm    
No problem. I haven't known about the max size either until I saw your question.

cheers,
Marco Bertschi

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