I call a specific webservice method from my android phone app and it always results in the error:
Object reference not set to an instance of an object
I call MANY different methods in this service with no problem, this is the only one that gives me an issue and I cannot track it down. The webservice is written in VB.NET, the phone app C#. Breakpoints confirm that all the data is being passed correctly, there is NO null data.
I created a "log" system where I can log messages to my database at certain places in my code. The messages are logged in the database, but the method, apparently, errors out on a call to a function within the method. I setup the webservice to be able to test it in the production environment remotely and it works EVERYTIME, yet when I call it from my phone app, I get the error. I'm stumped. This is the error message I get:
Source: System.Web.Services Description:Server was unable to process request. Object reference not set to an instance of an object. Target Site:System.Object[] ReceiveResponse(System.Net.WebResponse, System.Web.Services.Protocols.SoapClientMessage, System.Web.Services.Protocols.SoapExtension[]) Call Stack: at System.Web.Services.Protocols.SoapHttpClientProtocol.ReceiveResponse (System.Net.WebResponse response, System.Web.Services.Protocols.SoapClientMessage message, System.Web.Services.Protocols.SoapExtension[] extensions) [0x001ed] in <6f5d26adf5754fd8a1fe9ebdbdc88f48>:0 at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke (System.String method_name, System.Object[] parameters) [0x000ad] in <6f5d26adf5754fd8a1fe9ebdbdc88f48>:0 at MyAndroidApp.DataInterfaceWeb.DataInterface.ProcessSubscription (System.String list1, System.String list2, System.String list3, System.String list4, System.String list5, System.String list6, System.String list7, System.String list8, System.String list9, System.String list10, System.String list11, System.String list12, System.String list13, System.String list14, System.String list15, System.String list16, System.String list17, System.String list18, System.String list19) [0x00001] in C:\Users\HP\source\repos\Projects\MyAndroidApp\MyAndroidApp\Web References\DataInterfaceWeb\Reference.cs:2308 at (wrapper remoting-invoke-with-check) MyAndroidApp.DataInterfaceWeb.DataInterface.ProcessSubscription(string,string,string,string,string,string,string,string,string,string,string,string,string,string,string,string,string,string,string) at MyAndroidApp.Subscription+<>c__DisplayClass24_0.b__1 (System.Object sender, System.EventArgs e) [0x001ee] in C:\Users\HP\source\repos\Projects\MyAndroidApp\MyAndroidApp\Subscription.cs:211
This is the Web method:
<WebMethod()>Public Function ProcessSubscription(ByVal list1 As String, ByVal list2 As String, ByVal list3 As String, ByVal list4 As String, ByVal list5 As String, ByVal list6 As String, ByVal list7 As String, ByVal list8 As String, ByVal list9 As String, ByVal list10 As String, ByVal list11 As String, ByVal list12 As String, ByVal list13 As String, ByVal list14 As String, ByVal list15 As String, ByVal list16 As String, ByVal list17 As String, list18 As String, list19 As String) As String Dim LogErrors As String = ConfigurationManager.AppSettings("LOG") Dim MyResponse As ANetApiResponse If LogErrors = "TRUE" Then LogError("Processing Subscription") '<-- this line is executed as this message appears in the database End If Try Dim amount As Decimal = Convert.ToDecimal(list16) ' I believe that this is the call that causes the error, yet calling ' the method directly via the browser works every time! Just won't ' work when I call the method from the android app. MyResponse = ChargeCreditCard.Run(amount.ToString, list11, list12, list19, list3, list4, list6, list7, list8, list9) Catch ex As Exception LogError(ex.Message) ' <--- never hits this line as nothing is logged after the "Processing subscription" log message End Try Dim returnmessage As String If MyResponse.messages.resultCode = messageTypeEnum.Ok Then returnmessage = "SUCCESSFUL" PaySubFee(list1, list2, list13) Else returnmessage = "The card was declined: " & "Error Code: " & MyResponse.messages.message(0).code End If Return returnmessage 'MyResponse.messages.resultCode ' 0 = ok, 1 = error Return result End Function
02-04-2020 08:19 AM
Ok, I got a little more information.
I test for MyRespose IsNot nothing and it is null. So that explains the error and I can code for it, but what I don't understand is why is the resopnse nothing with the android call and is ok with in the browser?
02-04-2020 09:05 AM
Ok, tracked down the problem to the line "controller.GetApiResponse()", when I run the code via the webservice browser interface, it returns data fine. When I run that code via the webservice interface via the android app it always returns null even though the exact same data is passed. I'm stumped on this one.
02-04-2020 11:00 AM