I'm trying to invoke a WCF service through HTTP POST, but the service returns a 400 error. I don't know whether this is due to the OperationContract or the way I'm doing the POST. This is what the contract looks like on the server-side:
[OperationContract, WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
Stream Download(string username, int fileid);
And here's how I'm trying to invoke the service through a test console app:
HttpWebRequest webRequest = WebRequest.Create("http://localhost:8000/File/Download") as
HttpWebRequest;
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
byte[] bytes = Encoding.ASCII.GetBytes("username=test&fileid=1");
Stream os = null;
webRequest.ContentLength = bytes.Length;
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
WebResponse webResponse = webRequest.GetResponse();
edit: I should make it clear that my goal is to test the service, and not to make it accept raw HTTP POSTs. If there's a better way I can test the service, please feel free to share.