Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
i, write  a  Wcf service for video uploding for andriod device. but when connect this service we get a error msg "Cannot process the message because the content type 'application/octet-stream' was not the expected type 'text/xml; charset=utf-8'". whats this error ??
help me...
Posted

1 solution

Well, the service response is always in XML, unless you explicitly specify the different type, i.e JSON.
Cannot process the message because the content type 'application/octet-stream' was not the expected type 'text/xml; charset=utf-8'
Now you're passing the octet-stream, which is not an XML. So you need to convert your stream to XML and pass it over WCF.

As you've not shared your code, it's hard to tell what you can do.

-KR
 
Share this answer
 
Comments
Mahesh Alappuzha 30-Oct-15 1:13am    
This is wcf Service Code


namespace FileUpload
{
[ServiceBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class FileUpload : IFileUpload
{
public void DoWork()
{
}

public RemoteFileInfo DownloadFile(DownloadRequest request)
{
RemoteFileInfo result = new RemoteFileInfo();
try
{
// get some info about the input file
string filePath = System.IO.Path.Combine(@"E:\", request.FileName);
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);

// check if exists
if (!fileInfo.Exists) throw new System.IO.FileNotFoundException("File not found", request.FileName);

// open stream
System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

// return result

result.FileName = request.FileName;
result.Length = fileInfo.Length;
result.FileByteStream = stream;
}
catch (Exception ex)
{

}
return result;

}



public void UploadFile(RemoteFileInfo request)
{
FileStream targetStream = null;
Stream sourceStream = request.FileByteStream;

string uploadFolder = @"E:\";
string filePath = Path.Combine(uploadFolder, request.FileName);

using (targetStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
//read from the input stream in 6K chunks
//and save to output stream
const int bufferLen = 65000;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
{
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
}

}
}
}
Mahesh Alappuzha 30-Oct-15 1:15am    
Andriod code


@SuppressLint({ "SimpleDateFormat", "NewApi" }) public String sendFileToServer(String request, String targetUrl) {
String response = "error";
Log.e("Image filename", request);
Log.e("url", targetUrl);
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
// DataInputStream inputStream = null;

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy);

String pathToOurFile = request;
String urlServer = targetUrl;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH:mm:ss");

int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1 * 1024;
try {
@SuppressWarnings("resource")
FileInputStream fileInputStream = new FileInputStream(new File(
pathToOurFile));

URL url = new URL(urlServer);
connection = (HttpURLConnection) url.openConnection();

// Allow Inputs & Outputs
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setChunkedStreamingMode(1024);
// Enable POST method
connection.setRequestMethod("POST");

connection.setRequestProperty("Connection", "Keep-Alive");
// connection.setRequestProperty("Content-Type",
// "multipart/form-data; boundary=" + boundary);
connection.setRequestProperty("ENCTYPE", "multipart/form-data");
connection.setRequestProperty("Content-Type","multipart/form-data;boundary=" + boundary);
connection.setRequestProperty("UploadFile", pathToOurFile);

outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(twoHyphens + boundary + lineEnd);

String connstr = null;
connstr = "Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
+ pathToOurFile + "\"" + lineEnd;
Log.i("Connstr", connstr);

outputStream.writeBytes(connstr);
outputStream.writeBytes(lineEnd);

bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];

// Read file
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
Log.e("Image length", bytesAvailable + "");
try {
while (bytesRead > 0) {
try {
outputStream.write(buffer, 0, bufferSize);
} catch (OutOfMemoryError e) {
e.printStackTrace();
response = "outofmemoryerror";
return response;
}
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
} catch (Exception e) {
e.printStackTrace();
response = "error";
return response;
}
outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens
+ lineEnd);

// Responses from the server (code and message)
int serverResponseCode = connection.getResponseCode();
String serverResponseMessage = connection.getResponseMessage();
Log.i("Server Response Code ", "" + serverResponseCode);
Log.i("Server Response Message", serverResponseMessage);

if (serverResponseCode == 200) {
response = "true";
}

String CDate = null;
Date serverTime = new Date(connection.getDate());
try {
CDate = df.format(serverTime);
} catch (Exception e) {
e.printStac
Mahesh Alappuzha 30-Oct-15 1:28am    
when open connection with service get response code 200,but in Server response error code 415
Krunal Rohit 30-Oct-15 1:28am    
As I said, you need to convert your stream to XML.

-KR
Mahesh Alappuzha 30-Oct-15 1:51am    
i want send 500mb data then can i use XML ??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900