我收到错误说"服务器无法处理请求。 --->实例失败。"当我尝试使用SOAP webservice上传图像时。
请我帮忙,因为我被困在这里。
这是我的代码:
private class UploadImage extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(UploadImageActivity.this);
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.setMessage("Please wait..");
progressDialog.show();
}
@Override
protected String doInBackground(String... params) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, baos);
//bMap is the bitmap object
byte[] imagebyte = baos.toByteArray();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("Email", UserContext.email);
request.addProperty("MobileNo", UserContext.mobilenumber);
request.addProperty("Image", imagebyte);
request.addProperty("Flage_InsertiedBy", UserContext.Flage_InsertiedBy);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
new MarshalBase64().register(envelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
webResponse = response.toString();
System.out.println("test response upload " + webResponse);
} catch (Exception e) {
System.out.println("test response upload ex " + e.getMessage());
}
return webResponse;
}
@Override
protected void onPostExecute(String result) {
progressDialog.dismiss();
}
答案 0 :(得分:0)
我将图像转换为字节数组并处理为。像魅力一样工作
String NAMESPACE = "http://Webservices.MyDomain.com/WebServices";
String METHOD_NAME = "UploadRequestImage";
String SOAP_ACTION = "http://Webservices.MyDomain.com/WebServices/UploadRequestImage";
String URL = "http://webservices.MyDomain.com/webservices/UpdateData.asmx";
SoapObject table = null; // Contains table of dataset that returned through SoapObject
SoapObject client = null; // Its the client petition to the web service
SoapObject responseBody = null; // Contains XML content of dataset
SoapSerializationEnvelope sse = null;
sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
new MarshalBase64().register(sse);
sse.addMapping(NAMESPACE, "movie", this.getClass());
//Note if class name isn't "movie" ,you must change
sse.dotNet = true; // if WebService written .Net is result=true
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 600000);
try {
client = new SoapObject(NAMESPACE, METHOD_NAME);
client.addProperty("TicketId", MyTicketId);
client.addProperty("UserId", UserId);
client.addProperty("imageBytes", ByteArray);
client.addProperty("FileName", "Image_" + SelectedId + ".jpg");
sse.setOutputSoapObject(client);
sse.bodyOut = client;
androidHttpTransport.call(SOAP_ACTION, sse);
// This step: get file XML
responseBody = (SoapObject) sse.getResponse();
// remove information XML,only retrieved results that returned
responseBody = (SoapObject) responseBody.getProperty(1);
// get information XMl of tables that is returned
table = (SoapObject) responseBody.getProperty(0);
}//try block
catch (Exception e) {
Log.d("ETC", e.getMessage());
return null;
}//catch
return table;