| |

VerySource

 Forgot password?
 Register
Search
View: 760|Reply: 6

"Object reference not set to an instance of an object" error, it kills me

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Canada

Post time: 2020-9-28 18:30:01
| Show all posts |Read mode
I wrote a project myself. A class provides a method to query from the database and return a string (using the pattern developed by others, I don’t know how the data comes out, so I just use it). Now if another web application references this class and calls this method, everything is normal. But if I use a web service project, refer to this class, return the string returned from the above class as a web method, reference the web service in the web application, call the method, and "Object reference not set to an instance of" will appear. an object" error. The error output with try is
System.Web.Services.Protocols.SoapException: Server was unable to process request. --> Object reference not set to an instance of an object. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at WSClient.RemotingServ.ServiceRemoting.GetOptionText() in C:\Inetpub\wwwroot\WSClient\Web References\RemotingClient.cs.uo1 at WSClient. TestRemoting.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\wsclient\testremoting.aspx.cs:line 58

Please master guidance. Because of business requirements, my webservice cannot directly access the database, and must get the things in the database through that intermediate class area!
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-9-30 22:30:01
| Show all posts
A very common code problem is that you have to create a new object and then reference it somewhere.
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-9-30 22:45:01
| Show all posts
No database processing in web service, is it normal
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Canada

 Author| Post time: 2020-10-1 01:30:01
| Show all posts
Because there should be no leakage, the same code, I don’t need webservice to adjust it, but webservice can’t work. After debugging and tracking, the process is the same, that is, a certain object returns empty, but I don’t know why.

No way, I can only access the database through the formed business tier, the web service itself cannot access it, I think there is nothing abnormal
Reply

Use magic Report

0

Threads

20

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-10-1 05:15:01
| Show all posts
The problem must be in your class

First look at this class of yours, is it wrong when using WS call
Reply

Use magic Report

0

Threads

20

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-10-1 06:15:01
| Show all posts
Paste your code, just paste the execution path in your class.
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-10-1 07:30:01
| Show all posts
In fact, the error in this class is that calling an object returns null. But the point is that I don't need to adjust the web service, this is where I wonder! I posted the code later, which is that tempInvokerFactory returned an error.

public string GetOption()
{
GATServiceInvoker invoker = GATInvoker();
Element element = invoker.ReadDiv("GATID_4ca9b6ce3f49420683ef982c30a5a1cb", "en");
string temp=((TextOptionElement)element.ConcreteElement).OptionText.ToString();
return temp;
}

private GATServiceInvoker GATInvoker()
{
if (tempGatService != null) return tempGatService;
tempGatService = GetInvokerFactory().GetGATServiceInvoker();
tempGatService.ErrorOccurred +=new ErrorOccurredEventHandler(ServiceInvoker_ErrorOccurred);
return tempGatService;
}

private ServiceInvokerFactory GetInvokerFactory()
{
if (tempInvokerFactory != null) return tempInvokerFactory;
tempInvokerFactory = new ServiceInvokerFactory( GetFactory() );
return tempInvokerFactory;
}

private ServiceFactory GetFactory()
{
if (tempFactory != null) return tempFactory;
tempFactory = new ServiceFactory();
return tempFactory;
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list