1

我有一个在我的 android 项目中使用的 Web 服务。我的网络服务中的一种方法在带有 ksoap2 的 android 中返回 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
4

1 回答 1

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;

}

希望能帮助到你。

于 2012-08-15T16:40:48.880 回答