Link to home
Start Free TrialLog in
Avatar of infotechelg
infotechelgFlag for United States of America

asked on

Stumped on Web Service Error in .NET

Hello,

I am completely stumped and baffled by this "Object reference not set to an instance of an object." error I'm receiving when I try to call a Webservice from my .NET code.

Here's what's odd:

1) It works fine in development and on staging. When I publish it live, I get the error.

2) I have two very similar methods in my Web Service that I'm calling. One works, the other doesn't.

Since I can't debug live, I put in code to write to a text file during each step of the process. It turns out, it's erroring out when I call the WebService method; it's not even getting into the Web service method. but, like I said, a very similar web service method is being called from a different .aspx page, and that works fine.

Here are the lines of code that are calling the Web Service methods. The first one is the one that doesn't work, the second is the one that does.

Bad:
     Log.AddToLogFile("Getting ready to call new WebService().DisplayProduct() ... genericId: " + genericId + "; systemId: " + systemId, null);
     rightSide.Text += new WebService().DisplayProduct(genericId, systemId);

Open in new window

The log gets updated, but then it immediately errors out on the next line.

Good:
     Log.AddToLogFile("Getting ready to call new WebService().DisplayGallery() ... genericId: " + genericId + "; systemId: " + systemId, null);
     rightSide.Text += new WebService().DisplayGallery(myGallery, genericId, systemId);

Open in new window

Again, this calls the method with no problem.

Method That Isn't Being Called:
    [WebMethod(EnableSession = true)]
    public string DisplayProduct(string genericId, string systemId)
    {
        Log.AddToLogFile("\nGot into WebService().DisplayProduct(). Getting ready to call the overloaded method: genericId: " + genericId + "; systemId: " + systemId, null);
        return DisplayProduct(genericId, systemId, null, null);
    }

Open in new window

It doesn't even get here because no log file entry is being created.

Method That Does Get Called:
    [WebMethod(EnableSession = true)]
    public string DisplayGallery(List<Gallery> myGallery, string genericId, string systemId)
    {
        Log.AddToLogFile("\nGot into WebService().DisplayGallery(). Getting ready to call the overloaded method: genericId: " + genericId + "; systemId: " + systemId, null);
        return DisplayGallery(myGallery, genericId, systemId, null, null);
    }

Open in new window

This gets called with no issues.

This makes absolutely no sense. Not just because one is working and the other isn't, but that this is only happening on the live server and it was working before.

Please help!
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Are you referring to the same webservice or does production have a different web service URL than say staging and dev?



Just an FYI I would create an instance of a webservice:
WebService ws = new WebService();

then call ws.DisplayProduct(...);
ws.DisplayGallery(...);

etc.

I would try pointing to the production URL on dev and see if you get the same results . . . it could be the webservice itself wasn't updated.  

Take baby steps, run the code with the parameters on the productionDB.  Do you get expected results?

Then invoke the webservice from the box itself passing in the ids manually, do you get the expected XML?

And finally make sure the production box is pointing to the webservice you just tested.
Avatar of infotechelg

ASKER

Thanks for the reply. I guess I'm not sure what you mean by "making sure the production box points to the web service". The Web Service (.asmx) is part of my .NET project that gets compiled. It's not separate or anything.

But your idea of running the Webservice manually is good. I'll try that.
The reference to the asmx can be re-pointed to any url that runs that web service.

EG:

I have a development box running webservice.asmx that I can add more functions to without breaking existing functionality.

When it comes time for production, I change the url to the production box with the same webservice.asmx.  If I don't update the asmx file, the new functionality won't be there.
I'm trying to access the Web Services through the browser so I can test (by the URL: http://myurl.com/Services/WebService.asmx) but am getting this error:

Unable to handle request.

Am I missing something from the .asmx file or the web.config file needed to make this work?
just a note . . . you can only hit it from localhost . . . so you'll need to remote into the machine in order to test.

But if you can't hit the webservice.asmx that's a great place to start.  You should always get back a page with at least the functions available to be called.
SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dan7el, I will certainly try that. However, the method that does work is overloaded, and that's not an issue. Also, if that were the case, wouldn't it error-out everywhere, not just in production?

EDIT: Dan7el, "OperationContract" isn't coming up in Intellisense and is returning an error.
"I would try pointing to the production URL on dev and see if you get the same results"

Sorry, but how do I do that? :)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, thanks Dan7el. I'll give it a shot.
Dan7el, well...good and bad news. The bad news is I'm still receiving the error. But, the good news is that the code actually got into the Web Service this time as the log file populated with text!

So, now it's just a matter of tracking that down.

Thanks!!