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!
infotechelgAsked:
Who is Participating?
 
Daniel Van Der WerkenConnect With a Mentor Independent ConsultantCommented:
You need to:
using System.ServiceModel;

for the OperationContract. This is typical for WCF services, but from what I can tell, it applies to ASMX (web services) as well.

Here's the deal: Overloading works but not with real services. If you are in any way using the DLL directly and not via a service reference, then overloading without the OperationiContract attribute will simply work.

My guess is that you are inadvertently using the DLL rather than the actual service in your non-production work. However, when you try to use it in production, you are, in fact, actually using the service and the "overload" fails. You need to basically "rename" the method and use the newly named method.

It's a big pain, I know.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0
 
infotechelgAuthor Commented:
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.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0
 
infotechelgAuthor Commented:
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?
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0
 
Daniel Van Der WerkenConnect With a Mentor Independent ConsultantCommented:
I think the problem is that you're calling a method that is overloaded and not overloading it properly.

Are you decorating the method with the appropriate OperationContract attribute?

[WebMethod(EnableSession = true)]
[OperationContract(Name="DisplayProductByTwoIDs")]
    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


Then, when you call it:

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

Open in new window


Otherwise, it won't work. You can't have identical named overloaded methods exposed via a web service.
0
 
infotechelgAuthor Commented:
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.
0
 
infotechelgAuthor Commented:
"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? :)
0
 
infotechelgAuthor Commented:
Ok, thanks Dan7el. I'll give it a shot.
0
 
infotechelgAuthor Commented:
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!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.