I am trying to post a json string to my wcf service. The issue is that my WCF method expects a Stream object and not just a JSON.
Here is the method header in WCF:
[WebInvoke(Method = "POST", UriTemplate = "person/delete", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Person DeletePerson(Stream streamdata)
Here is what I have been trying:
HttpPost request = new HttpPost(SERVICE_URI + uri);
InputStream is = new ByteArrayInputStream(data.getBytes());
InputStreamEntity ise = new InputStreamEntity(is, data.getBytes().length);
ise.setContentType("application/x-www-form-urlencoded");
ise.setContentEncoding(HTTP.UTF_8);
request.setEntity(ise);
HttpResponse response = null;
try {
response = client.execute(request);
} catch (ClientProtocolException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
I get 400 bad request with this and everything else ive tried. Could someone please help me get this working!? Also, it has to be done with HttpClient because I have custom authentication code working with it.
1 Answer