Web Service在Android中返回null

时间:2012-08-15 14:17:56

标签: android web-services ksoap2 android-ksoap2

我有一个我在android项目中使用的Web服务。我的web服务中的一个方法在android中使用kso​​ap2返回null。当我调试项目时,信封会像这样返回:

GPSYerBilgisiGetirResponse{GPSYerBilgisiGetirResult=anyType{}; }

在android之外,我运行Web服务并为方法提供参数,返回如下数据:

<ArrayOfFirma xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Firma>
<gpsilce>BEYOĞLU</gpsilce>
<gpssemt>KASIMPAŞA</gpssemt>
</Firma>
</ArrayOfFirma>

这是我使用连接到网络服务的功能

private String[] konumGetir(String ParamPK){
    PropertyInfo pk = new PropertyInfo();
    pk.name= "pk";
    pk.setValue(ParamPK);
    pk.type = PropertyInfo.STRING_CLASS;

    SoapObject request = new SoapObject(NAMESPACE, "GPSYerBilgisiGetir");
    request.addProperty(pk);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.bodyOut=request;
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;

   try {

   androidHttpTransport.call("http://tempuri.org/GPSYerBilgisiGetir", envelope);
   SoapObject response = (SoapObject) envelope.getResponse();
   konumList=new String[1];

   for(int i=0;i<response.getPropertyCount();i++){    
       Object property = response.getProperty(i);
       if(property instanceof SoapObject){
           SoapObject firmalar = (SoapObject) property;
           konumList[0]=firmalar.getProperty("gpssemt") + "-" + firmalar.getProperty("gpsilce");
       }
    }
} 
    catch (Exception e) {           
        e.printStackTrace();
   }
    return konumList;

    }

这是我的网络服务方法:

<WebMethod()> _
    Public Function GPSYerBilgisiGetir(ByVal pk As String) As List(Of Firma)
        Dim konumlist As New List(Of Firma)

        Dim dg As New dgetir("SELECT DISTINCT ILCE,SEMT FROM GPSYERBILGISI WHERE PK='" + pk + "'")
        While dg.dtr.Read
            Dim gpskonum As New Firma

            gpskonum.gpsilce = dg.dtr.Item("ILCE")
            gpskonum.gpssemt = dg.dtr.Item("SEMT")
            konumlist.Add(gpskonum)

        End While
        dg.close()

        Return konumlist

    End Function

1 个答案:

答案 0 :(得分:0)

试试这段代码。

private String[] konumGetir(String ParamPK){
   SoapObject request = new SoapObject(NAMESPACE, "GPSYerBilgisiGetir");
   request.addProperty("pk", ParamPK);
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.dotNet = true;
   envelope.setOutputSoapObject(request);
   HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  try {
     androidHttpTransport.call(SOAP_ACTION_NAME, envelope);
     SoapObject result = (SoapObject) envelope.getResponse();
     int childCount = result.getPropertyCount();
     konumList = new String[childCount];
     SoapObject tempArray[] = new SoapObject[childCount];
     int i;
     for (i = 0; i < childCount; i++) {
        tempArray[i] = (SoapObject) result.getProperty(i);
        konumList[i] = tempArray.getProperty(0).toString();
     }
  } catch (Exception e) {           
     e.printStackTrace();
  }
  return konumList;

}

希望它有所帮助。

相关问题