1

我想通过使用 ksoap 将整数值数组传递给排序 web 服务。在服务器端测试时,我的应用程序成功运行。但是,客户端程序在调用“androidHttpTransport.call(SOAP_ACTION,envelope)”方法后会阻塞。任何人都可以指导我做错了什么。谢谢

在下面找到我的 android 应用程序代码:

public void onClick(View arg0) {
         try {
             KVMInterface ob=new KVMInterface();    
             PropertyInfo pi = new PropertyInfo();
                pi.setName("ob");
                pi.setValue(ob);
                pi.setType(ob.getClass());
              METHOD_NAME = "Sort";  
              SOAP_ACTION = NAMESPACE+METHOD_NAME;

             SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);            
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true;
               request.addProperty(pi);
                envelope.setOutputSoapObject(request);
                envelope.addMapping(NAMESPACE, "ob",new KVMInterface().getClass());

                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapObject response = (SoapObject)envelope.getResponse();
                System.out.println("Response Received");
                                 SoapObject  ks = ( SoapObject ) envelope.bodyIn; 
                ob=(KVMInterface) ks.getProperty(0);
                System.out.println(ob);

其中客户端上的KVMInterface类如下:

public class KVMInterface implements KvmSerializable
{
public int [] a=new int[5]; 
public KVMInterface()
{
            initialize();
    }

@Override
public Object getProperty(int arg0) {
    // TODO Auto-generated method stub
    return a;
}

@Override
public int getPropertyCount() {
    // TODO Auto-generated method stub
    return 1;
}

@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
    // TODO Auto-generated method stub
    arg2.type=PropertyInfo.INTEGER_CLASS;
    arg2.name="Array";
}

@Override
public void setProperty(int arg0, Object arg1) {
    // TODO Auto-generated method stub

}
private void initialize()
{
for(int i=0;i<a.length;i++) 
    a[i]=i;
}

}

以下是 webserver 应用上 Sort 方法的代码

[WebMethod (EnableSession = true)]

    public KVMInterface Sort(KVMInterface ob)
    {
         Random random = new Random();

         for (int i = 0; i < a.Length; i++)
         {
             a[i] = random.Next(1, a.Length);
             }
        KVMInterface obkvm = (KVMInterface)ob;
        int temp = 0;

        for (int i = 0; i < obkvm.a.Length; i++)
        {
            for (int j = i + 1; j < obkvm.a.Length; j++)
            {
                if (obkvm.a[i] > obkvm.a[j])
                {
                    temp = obkvm.a[i];
                    obkvm.a[i] = obkvm.a[j];
                    obkvm.a[j] = temp;
                }
            }

        }
        return ob;
    }

public class KVMInterface
    {
        public int[] a = new int[5];

        public KVMInterface()
        {
            intialize();
        }
        void intialize()
        {
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = i;
            }
        }
    }
4

0 回答 0