2011-12-15 2 views
0

도움이 필요합니다.Android 클라이언트 웹 서비스

웹 서비스에 바이트 배열과 하나의 문자열을 보내는 하나의 응용 프로그램 인 android를 개발 중입니다. 내 안드로이드 코드의

부품 :

private static final int SELECT_VIDEO = 100; 
private static final String NAMESPACE = "org.me.WebService"; 
private static final String URL = "http://192.168.1.4:8084/MyTubeWebService/MyTubeService?wsdl";  
private static final String SOAP_ACTION = "MyTubeService"; 
private static final String METHOD_NAME = "upArquivoVideo"; 

     //(...) 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  
      SoapSerializationEnvelope envelope = 
       new SoapSerializationEnvelope(SoapEnvelope.VER11); 

      request.addProperty("arquivoVideo",video); 
      request.addProperty("descricao", "teste"); 
      envelope.setOutputSoapObject(request); 

      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

      try { 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       //androidHttpTransport.call(NAMESPACE+"/"+METHOD_NAME,envelope); 
       SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; 
       text.setText("Received :" + resultsRequestSOAP.toString()); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

및 웹 서비스 코드 :

@WebService(serviceName = "MyTubeService") 
public class MyTubeService { 

/** 
* Operação de serviço web 
*/ 
@WebMethod(operationName = "upArquivoVideo") 
@Oneway 
public void upArquivoVideo(@WebParam(name = "arquivoVideo") byte[] arquivoVideo, @WebParam(name = "descricao") String descricao) { 

    if (arquivoVideo.length > 0){ 
     System.out.println("OK!"); 
    }else{ 
     System.out.println("Erro"); 
    } 

    System.out.println("desricao = " + descricao); 

} 

로그 고양이 한 번에 파견 예외 소켓 시간 초과 ... 그리고 내 마지막 시험 파견에 the RuntimeException : 직렬화 할 수 없습니다

내가 뭘 잘못하고있어? 그것은 안드로이드 측면에 있습니까? 또는 웹 서비스 측면에서?

답변

0

먼저 답을 얻으려면 수락 비율을 높여야합니다.

ksoap을 사용하여 웹 서비스에 문자열과 바이트 배열을 보내는 데 문제가 있음을 확인했습니다.

private String doLogin(String user_id, String password) 
    { 
    SoapPrimitive resultstring = null; 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty("user", user_id); 
    request.addProperty("password", password); 
    SoapSerializationEnvelope soapenvelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11); 
    soapenvelope.dotNet = true; //only if it is .net webservice              
    soapenvelope.setOutputSoapObject(request); 

    AndroidHttpTransport httptransport = new AndroidHttpTransport(URL); 
    httptransport.debug = true; 

    try { 
      httptransport.call(SOAP_ACTION, soapenvelope); 
      resultstring = (SoapPrimitive) soapenvelope.getResponse(); 
    //change above line depending upon the response you get             


    } 
    catch (SocketException ex) { 
     Log.e("Error : " , "Error on soapPrimitiveData() " + ex.getMessage()); 
     ex.printStackTrace(); 
    } catch (Exception e) { 
     Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage()); 
     e.printStackTrace(); 
    } 
    return resultstring+""; 

    } 

는 마찬가지로, 나는 당신이 바이트 배열을 보내도록 코드를 작성할 수 있기를 바랍니다 :

다음은 웹 서비스에 문자열을 보낼 수있는 한 가지 방법입니다. 많은 자습서와 코드 스 니펫이 도움이됩니다. 이 도움이

희망,

건배

관련 문제