Saturday, April 27, 2013

[android help] Send large amount of data to WCF service with stream from android


I am currently working on a wcf service which requires to read data from database via entity framework and pass the data back to the client(in my case which is Android). The service supports REST and SOAP. The wcf service is hosted under windows service. However, I had no success to upload the stream to the WCF and download streamed data from the WCF Service to android. I only show the function that upload the streamed data to wcf service below.


Does anyone know why it doesn't work? I tried to pass the streamed data from android to wcf service or from wcf service to android. They both don't work. The code i used for WCF and android is as follows:


Does webhttpbinding support stream as well?


In my WCF Service, the app.config is below:






















































type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.84.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />











The code of the service interface:



[OperationContract(Action = "UploadFile", IsOneWay = true)]
[WebInvoke(Method = "POST", UriTemplate = "/Fileupload", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
void AddMonitoringData(Stream stream);


The code of the service:



public void AddMonitoringData(Stream stream)
{
StreamReader reader = new StreamReader(stream);
string text = reader.ReadToEnd();

File.AppendAllText("c:\\wcf_service\\test.txt", text);

}


Here is my android code in Java for sending the streamed data to wcf service:



DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
String xml ="valid xml here. Testing here.";
InputStream is = new ByteArrayInputStream(xml.getBytes());

// Send GET request to /GetPlates

String XMLURL = "http://xxxx:8733/iPhysio_Wcf_Service/Service/XMLService";
HttpPost request = new HttpPost(XMLURL + "/Fileupload");
request.setHeader("Accept", "binary/octet-stream");
request.setHeader("Content-type", "binary/octet-stream");
InputStreamEntity reqEntity = new InputStreamEntity(is, -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(false); // Send in multiple parts if needed
request.setEntity(reqEntity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);


Thanks for any help in advance.



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...