Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML WCF
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 4-Mar-13 5:45am
IviKAZAZI1.5K
Comments
rajkumar sharma at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
IviKAZAZI at 6-Mar-13 4:58am
   
the problem was the max side of data allowed :( thnx for the solution
Marco Bertschi at 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)



Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 12 Jun 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100