0

我正在开发一个应用程序,它从 android 获取位置详细信息并将其发送到 vb.net webservice 以将其插入数据库。当我出于测试目的访问 localhost Web 服务时,我成功地将位置详细信息插入到数据库中。但是当我调用实际的网络服务器即http://www.enoxonline.in/webservice.asmx?op=SetLocationForAndroid时,我得到了以下异常。

05-27 12:21:37.477: I/System.out(276): SetLocationForAndroid{Latitude=37.422005; Longitude=-122.084095; sAddress=Charleston Road, Mountain View, San Jose; sLocality=California; sCountry=United States; sUserId=1004; }
05-27 12:21:39.998: E/Error :(276): Exception: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Exception: Object reference not set to an instance of an object.
05-27 12:21:39.998: E/Error :(276):    at WebService.SetLocationForAndroid(String Latitude, String Longitude, String sAddress, String sLocality, String sCountry, String sUserId)
05-27 12:21:39.998: E/Error :(276):    --- End of inner exception stack trace ---
05-27 12:21:39.998: W/System.err(276): SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Exception: Object reference not set to an instance of an object.
05-27 12:21:40.008: W/System.err(276):    at WebService.SetLocationForAndroid(String Latitude, String Longitude, String sAddress, String sLocality, String sCountry, String sUserId)
05-27 12:21:40.008: W/System.err(276):    --- End of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.Node@43e626e0

我浏览了很多帖子,但我对这个问题没有清楚的了解/有人可以告诉我出了什么问题吗?

我的网络服务代码:

<WebMethod()> _
    Public Function SetLocationForAndroid(ByVal Latitude As String, ByVal Longitude As String, ByVal sAddress As String, ByVal sLocality As String, ByVal sCountry As String, ByVal sUserId As String) As String

        Dim sdr As New DataSet()
        Dim dt As New DataTable()
        Dim dl As New DL.clsDataLayer
        Dim strquery As String

        Dim sLatitude As Double = CDbl(Latitude)
        Dim sLongitude As Double = CDbl(Longitude)

        'Dim longitude = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng").InnerText
        Try
            With dl
                '.SqlQuery = "INSERT INTO MAP (LATITUDE,LONGITUDE,SERVER_DATE,ADDRESS,LOCALITY,COUNTRY,USER_ID,WEB_ENTRY) VALUES (" + dLatitude.ToString() + "," + dLongitude.ToString() + ",getdate(),'" + sAddress.Replace("'", "''") + "','" + sLocality.Replace("'", "''") + "','" + sCountry.Replace("'", "''") + "','" + sUserId + "',0 )"
                .SqlQuery = "INSERT INTO MAP (LATITUDE,LONGITUDE,SERVER_DATE,ADDRESS,LOCALITY,COUNTRY,USER_ID,WEB_ENTRY) VALUES (" + sLatitude.ToString + "," + sLongitude.ToString + ",getdate(),'" + sAddress.Replace("'", "''") + "','" + sLocality.Replace("'", "''") + "','" + sCountry.Replace("'", "''") + "','" + sUserId + "',0 )"
                strquery = "INSERT INTO MAP (LATITUDE,LONGITUDE,SERVER_DATE,ADDRESS,LOCALITY,COUNTRY,USER_ID,WEB_ENTRY) VALUES (" + sLatitude.ToString + "," + sLongitude.ToString + ",getdate(),'" + sAddress.Replace("'", "''") + "','" + sLocality.Replace("'", "''") + "','" + sCountry.Replace("'", "''") + "','" + sUserId + "',0 )"
                sdr = .fnGetData
            End With
            Return strquery

            'Dim conn As New SqlConnection
            'conn.ConnectionString = "Data Source = 62.75.229.51; Initial Catalog = Silver_WebPH; User id =Silver_Webph; password =sbyadmin1"
            'Dim strSql As String = "INSERT INTO MAP (LATITUDE,LONGITUDE,SERVER_DATE,ADDRESS,LOCALITY,COUNTRY,USER_ID,WEB_ENTRY) VALUES (" + sLatitude.ToString + "," + sLongitude.ToString + ",getdate(),'" + sAddress.Replace("'", "''") + "','" + sLocality.Replace("'", "''") + "','" + sCountry.Replace("'", "''") + "','" + sUserId + "',0 )"
            'conn.Open()
            'Dim cmd As New SqlCommand
            'cmd.Connection = conn
            'cmd.CommandText = strSql
            'cmd.CommandType = CommandType.Text
            'cmd.ExecuteNonQuery()
            'Return True
        Catch ioEx As IO.IOException
            ' Handle other non-specific IO Exceptions here.
            Throw New Exception(ioEx.Message.ToString)
        Return strquery     
            'Return ioEx.Message.ToString

        Catch ex As Exception
            ' Handle any other non-IO Exception here.
            Throw New Exception(ex.Message.ToString)
        Return strquery     
            'Return ex.Message.ToString
        End Try

    End Function

我调用网络服务的Android代码......

private String sendLocation(String latitude, String longitude, String sAddress, String sLocality, String sCountry, String sUserId)
    {
/*      final String NAMESPACE = "http://tempuri.org/";
        final String URL = "http://10.0.2.2:25722/NewLocationMap/Service.asmx";
        final String SOAP_ACTION = "http://tempuri.org/SetLocationForAndroid";
        final String METHOD_NAME = "SetLocationForAndroid";
*/  
        final String NAMESPACE = "http://www.enoxonline.in/";
        final String URL = "http://www.enoxonline.in/webservice.asmx";
        final String SOAP_ACTION = "http://tempuri.org/SetLocationForAndroid";
        final String METHOD_NAME = "SetLocationForAndroid";     

        try
        {
            SoapObject request = new SoapObject (NAMESPACE, METHOD_NAME);
            PropertyInfo pi = new PropertyInfo();
            pi.setType(String.class);
            pi.setName("Latitude");
            pi.setValue(latitude);
            request.addProperty(pi);
//          request.addProperty("Latitude",latitude);
            pi = new PropertyInfo();
            pi.setType(String.class);
            pi.setName("Longitude");
            pi.setValue(longitude);
            request.addProperty(pi);
//          request.addProperty("Longitude", longitude);
            pi = new PropertyInfo();
            pi.setType(String.class);
            pi.setName("sAddress");
            pi.setValue(sAddress);
            request.addProperty(pi);
//          request.addProperty("Longitude", longitude);
            pi = new PropertyInfo();
            pi.setType(String.class);
            pi.setName("sLocality");
            pi.setValue(sLocality);
            request.addProperty(pi);
//          request.addProperty("Longitude", longitude);
            pi = new PropertyInfo();
            pi.setType(String.class);
            pi.setName("sCountry");
            pi.setValue(sCountry);
            request.addProperty(pi);
//          request.addProperty("Longitude", longitude);
            pi = new PropertyInfo();
            pi.setType(String.class);
            pi.setName("sUserId");
            pi.setValue(sUserId);
            request.addProperty(pi);
//          request.addProperty("sUserId", UserId);


            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet=true;
            envelope.xsd = NAMESPACE;
            envelope.enc = "http://schemas.datacontract.org/2004/07/Entity";
            envelope.setAddAdornments(false);
            envelope.implicitTypes = true;
            envelope.setOutputSoapObject(request);
            System.out.println(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            androidHttpTransport.call(SOAP_ACTION, envelope);
            return envelope.getResponse().toString();
        }
        catch(Exception ex)
        {
            Log.e("Error : " , "Exception: " + ex.getMessage());
            ex.printStackTrace();
            return ex.getMessage();
        }
    }
4

0 回答 0