Android客户端Web服务

Android客户端Web服务,android,web-services,Android,Web Services,我需要一些帮助 我正在开发一个android应用程序,它向Web服务发送一个字节数组和一个字符串 我的部分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/MyTu

我需要一些帮助

我正在开发一个android应用程序,它向Web服务发送一个字节数组和一个字符串

我的部分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();
            }
和web服务代码:

@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);

}
日志cat一次性分派异常套接字超时。。。在我的上一次测试中,运行时异常:无法序列化


我做错了什么?它在安卓端吗?或者在web服务方面?

首先,您需要提高接受率才能获得答案

我发现您在使用ksoap向web服务发送字符串和字节数组时遇到问题

以下是向web服务发送字符串的一种方法:

   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+"";

    }
同样,我希望您可以编写一个代码来发送字节数组。有许多教程和代码片段可以帮助您

希望这有帮助

干杯