Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3243728
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:28:02+00:00 2026-05-17T18:28:02+00:00

Got an error while trying to invoke the webservice System.NullReferenceException: Object reference not set

  • 0

Got an error while trying to invoke the webservice

“System.NullReferenceException: Object reference not set to an instance of an object.”
Error on this line

if (Authentication.Username == "x" &&
            Authentication.Password == "y")

what does this mean?


[WebService(Namespace = "https://domain.com")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Testing : System.Web.Services.WebService
{
    public TestAuthHeader Authentication;
    public class TestAuthHeader : SoapHeader
    {
        public string Username;
        public string Password;
    }

    [WebMethod]
    [SoapHeader("Authentication")]
    public string TestService()
    {
        if (Authentication.Username == "x" &&
            Authentication.Password == "y")
        {
            return "OK";
        }
        else
        {
            return "Access Denided";
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:28:03+00:00Added an answer on May 17, 2026 at 6:28 pm

    Try moving the definition of class TestAuthHeader outside of the web service itself…

    Also, try testing unknown headers to see if Authentication is ending up there…

    [WebMethod]
    [SoapHeader("Authentication")]
    [SoapHeader("unknownHeaders",Required=false)]
    public string TestService()
    {
       foreach (SoapUnknownHeader header in unknownHeaders) {
          // Test header
          Debug.Write(header.Element.Name);
       }
    }
    

    Other than that, can we see the code where you’re calling into the web service?

    *Edit *

    If you’re not doing anything on the client side to create an instance of TestAuthHeader and set its properties, you’re going to have a null reference on the service side. From the MSDN example of using SoapHeaders (client code):

    MyHeader mySoapHeader = new MyHeader();
    
    // Populate the values of the SOAP header.
    mySoapHeader.Username = Username;
    mySoapHeader.Password = SecurelyStoredPassword;
    
    // Create a new instance of the proxy class.
    MyWebService proxy = new MyWebService();
    
    // Add the MyHeader SOAP header to the SOAP request.
    proxy.MyHeaderValue = mySoapHeader;
    
    // Call the method on the proxy class that communicates with
    // your Web service method.
    string results = proxy.MyWebMethod();
    

    All you really need is:

    public string TestService()
    {
        if (Authentication == null) {
            return "Access is denied";
        }
    
        // ... the rest of your code
    

    This will handle the scenario of where the client doesn’t set an authentication object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
Got this error today while trying to build a project with checkstyle. This works
Permission denied (publickey,keyboard-interactive) got this error while i am trying to cvs checkout from
I got an error today while trying to do some formatting to existing code.
While working on an existing project I suddenly got the following error when trying
I got this error today when trying to open a Visual Studio 2008 project
I got this error when trying to update an image. It was a cross-thread
I have got an error while trying to upgrade our large project to SL4.
I have got an(other) error while trying to upgrade our large project to SL4.
I am getting this error while trying to Parse the Xml response from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.