Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Stumped on Web Service Error in .NET

Posted on 2014-04-21
11
Medium Priority
?
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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
 
LVL 20

Assisted Solution

by:Daniel Van Der Werken
Daniel Van Der Werken earned 2000 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 2000 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

When ransomware hits your clients, what do you do?

MSPs: Endpoint security isn’t enough to prevent ransomware.
As the impact and severity of crypto ransomware attacks has grown, Webroot fought back, not just by building a next-gen endpoint solution capable of preventing ransomware attacks but also by being a thought leader.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 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