I have a wcf rest service, which I created a MemoryStream for one of my operation contracts that has an object, which encapsulates many properties. This is a GET HTTP request for data to the client (Android music app).
I've wrote some code to take my service side MemoryStream into the java based application, but I am not quite sure how I supposed to manage the conversion of the MemoryStream to a InputStreamArray. Two different languages (c# & java). Can anybody help out with some code example. I will post my code base if anyone wants to see it, but it pretty complex to try arranging it here and making good sence to others.
Here below is my output of my wcf message, which is envolope into a JSON format. Anybody help will be greatly appretiated. Thanks!
Here is my wcf web servie JSON format before processing my generic List Object into a MemoryStream.
LoadTracksByAlbumResult: [{AlbumCoverPhotoUrl: "/UploadContents/AlbumCoverPhoto/2135/Sauce Walka - The Sauce Father.jpg",…},…]
2. 0: {AlbumCoverPhotoUrl: "/UploadContents/AlbumCoverPhoto/2135/Sauce Walka - The Sauce Father.jpg",…}
1. AlbumCoverPhotoUrl: "/UploadContents/AlbumCoverPhoto/2135/Sauce Walka - The Sauce Father.jpg"
2. AlbumID: 2135
3. AlbumName: "Sauce Walka - The Sauce Father"
4. Artists: "(Sauce Walka . )"
5. CreatedBy: 0
6. CreatedOn: "6/5/2017"
7. DiscJockeyName: "(No DJ. )"
8. DjID: 23
9. DownloadStatus: false
10. TotalStreams: "1039"
11. TrackDescription: "Description 1"
12. TrackID: 35094
13. TrackStatus: true
14. TrackTitle: "01-Sauce_Walka-We_Did_It"
15. TrackUrl: "/UploadContents/AlbumTracks/2135/01-Sauce_Walka-We_Did_It.mp3"
16. UpdatedBy: 0
17. UpdatedOn: ""
3. 1: {AlbumCoverPhotoUrl: "/UploadContents/AlbumCoverPhoto/2135/Sauce Walka - The Sauce Father.jpg",…}
4. 2: {AlbumCoverPhotoUrl: "/UploadContents/AlbumCoverPhoto/2135/Sauce Walka - The Sauce Father.jpg",…}
5. 3: {AlbumCoverPhotoUrl: "/UploadContents/AlbumCoverPhoto/2135/Sauce Walka - The Sauce Father.jpg",…}
6. 4: {AlbumCoverPhotoUrl: "/UploadContents/AlbumCoverPhoto/2135/Sauce Walka - The Sauce Father.jpg",…}
7. 5: {AlbumCoverPhotoUrl: "/UploadContents/AlbumCoverPhoto/2135/Sauce Walka - The Sauce Father.jpg",…}
And here below is my wcf web servie JSON format wrapped into a MemoryStream.
What I have tried:
{LoadTracksByAlbumResult: {__identity: null,…}}
LoadTracksByAlbumResult: {__identity: null,…}
1. __identity: null
2. _buffer: [91, 123, 34, 84, 114, 97, 99, 107, 73, 68, 34, 58, 51, 53, 48, 57, 52, 44, 34, 84, 114, 97, 99, 107,…]
3. _capacity: 7522
4. _expandable: false
5. _exposable: false
6. _isOpen: true
7. _length: 7522
8. _origin: 0
9. _position: 0
10. _writable: true
Partial code from the server side of the memorystream below. Prepares a Data object for transmission over the wire.
Function implementation below:
byte[] byteArray = new byte[4000];
var json1 = new JavaScriptSerializer().Serialize(loadAlbumTracksList1);
byteArray = Encoding.UTF8.GetBytes(json1);
MemoryStream stream = new MemoryStream(byteArray);
return stream;
Client side java: Consuming for chuncks of data, so that performance is good for listening to mp3 files off the server. This is partial code below.
The String responsible parameter is where the memoryStream enter after it goes through the main Network (url, hostname, endpoint, port # and etc. are process here) of the application. Below is a aditional network for the stream process only, even though I wrote the code to accept 2 other wcf web service calls, which are coming from the server buffered. Can you please assist? I know I receive an error saying that the charset is not mappable.
public String getStream(String responseBody) {
String result = "";
InputStream inputStream = null;
try {
inputStream = new ByteArrayInputStream(responseBody.getBytes(), 0, 0);
result = convertInputStreamToString(inputStream);
}
catch(Exception ex)
{
Log.e("Exception",ex.getLocalizedMessage());
}
finally{
if(inputStream!=null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
private static String convertInputStreamToString(InputStream inputStream) throws IOException {
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream) );
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null)
result += line;
inputStream.close();
return result;
}
@Override
public void onRequestSuccess(String responseBody, String type) {
NetworkClient streamProcess = new NetworkClient();
String streamResponse = streamProcess.getStream(responseBody);
JSONObject obj = CommonServices.stringToJSON(streamResponse);
if(obj != null){
switch (type) {
case "loadtrack":
loadGridFromSavedJSONData(obj);