Solved

Stumped on Web Service Error in .NET

Posted on 2014-04-21
11
426 Views
Last Modified: 2014-04-21
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!
0
Comment
Question by:infotechelg
  • 6
  • 3
  • 2
11 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40012765
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
 

Author Comment

by:infotechelg
ID: 40012772
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
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40012781
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
 

Author Comment

by:infotechelg
ID: 40012833
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
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40012867
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 20

Assisted Solution

by:Daniel Van Der Werken
Daniel Van Der Werken earned 500 total points
ID: 40012954
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
 

Author Comment

by:infotechelg
ID: 40013063
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
 

Author Comment

by:infotechelg
ID: 40013108
"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
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 40013275
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
 

Author Comment

by:infotechelg
ID: 40013284
Ok, thanks Dan7el. I'll give it a shot.
0
 

Author Comment

by:infotechelg
ID: 40013314
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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now