2017-03-02 68 views
0

我收到一个错误,提示“服务器无法处理请求--->实例失败。”当我尝试使用SOAP webservice上传图片时。使用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

'request.addProperty(“Image”,imagebyte);'。认为你只能发送文本到肥皂服务器。不是字节。编译器会尝试通过将代码转换为'request.addProperty(“Image”,imagebyte.toString());'来创建字符串。但是,然后不会将字节数组的内容作为字符串发送,而是像@ 12345ade这样的字符串,它是数组的Java标识符。请打印imagebyte.toString()来查看。 – greenapps

回答

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; 
相关问题