vendredi 2 août 2019

How to fix 'Object reference not set to an instance of an object' in C# web service?

I have web service created in C# and i need to create a client using PHP. Since I cannot connect and use functions and methods in web service from PHP i am created my own Web Service in C# and I can manage almost all methods without issues. I can use all method which returns data as list and use that data as an array in PHP. What i can't do is I need to send some data and save it in a database that Web Service use it.

I can successfully send all necessarily data but when i call

ServisSonucOfDenetimKayitSonuc8Zb117hL denkayit = badsClient.AsansorDenetimKayit(dkayit); 

method to save it gives me 'Object reference not set to an instance of an object' error.

When I debug I can see all data sent to that method and I can see them on a breakpoint line.

I don't know what else to do please provide me some solution i can use.

Thanks in advance.

serviceConnect(username, password);



        [WebMethod]
        public void serviceConnect(string usr, string pwd)
        {
            try
            {
                BstbAsansorDenetimServisClient Client = new BstbAsansorDenetimServisClient();

                //var myEndpointBehavior = new SimpleEndpointBehavior();

                //client.Endpoint.Behaviors.Add(myEndpointBehavior);
                Client.ClientCredentials.UserName.UserName = usr;
                Client.ClientCredentials.UserName.Password = pwd;

                var basicHttpBinding = new BasicHttpBinding(
                              BasicHttpSecurityMode.TransportWithMessageCredential);
                basicHttpBinding.Security.Message.ClientCredentialType =
                                                     BasicHttpMessageCredentialType.UserName;
                badsClient = Client;
            }
            catch (FaultException<ServiceException> fe)
            {
                string hata = "TumIlleriSorgula[FaultException]: " + fe.Detail.Message +
                    "\r\nTumIlleriSorgula[FaultException]: " + fe.Detail.DebugInfo +
                    "\r\nTumIlleriSorgula[FaultException]: " + fe.Code.Name;
                System.Diagnostics.Debug.WriteLine(hata);
            }
            catch (Exception se)
            {
                string hata = "TumIlleriSorgula[FaultException]: " + se.Message +
                    "\r\nTumIlleriSorgula[FaultException]: " + se.InnerException +
                    "\r\nTumIlleriSorgula[FaultException]: " + se.Source;
                System.Diagnostics.Debug.WriteLine(hata);
            }
        }

 sonuc += dkayit.DenetimKayitDetayAsansorBilgi[0].KimlikNumarasi;
                        sonuc += dkayit.DenetimKayitDetayBakimSozlesme[0].TseBelgeDurum;
                        sonuc += dkayit.DenetimKayitDetayBinaSorumlusuBilgileri[0].BinaSorumluAdSoyad;
                        sonuc += dkayit.DenetimKayitDetayFirmaBilgi[0].BakimFirmaAd;
                        sonuc += dkayit.DenetimKayitDetaySoru[0].SoruSkala;
                        sonuc += dkayit.DenetimKayitDetayTechizatBilgi[0].DemirbasNo;
                        sonuc += dkayit.DenetimKayitSonuc[0].DenetimKayitId;
                        sonuc += dkayit.DenetimTarih;
                        sonuc += "<br>[badsClient.AsansorDenetimKayit] [CommunicationState]: Current state: <br>" + badsClient.State.ToString();

                        ServisSonucOfDenetimKayitSonuc8Zb117hL denkayit = badsClient.AsansorDenetimKayit(dkayit); --> where I am getting error...




Aucun commentaire:

Enregistrer un commentaire