1

I' m trying to do something but I'm not sure if it is allowed in c# here is what I'm tring:

I have a Web Method which is not a static here it is:

   [WebMethod]
    public Byte[] recStuff(Byte[] recstuffile)
    {
        myfile = Unzip(muStuff);

        return null;
    }

and here is my client:

 public static  XmlDataService.StufServiceSoapClient lhaservice = null;
        public static void Autoupload()
        {
            string fileContents = File.ReadAllText(XMLStuffName);
            string text = fileContents;
            byte r2 = Zip(text);
            lhaservice.recStuff(r2);
        }

I am getting Error that:

Object reference not set to an instance of an object.

what can I do here?

2
  • What is lhaservice? Commented Jun 11, 2013 at 11:08
  • 2
    Check lhaservice != null. If not initialize it. Commented Jun 11, 2013 at 11:09

2 Answers 2

2

It is very logical. lhaservice = null. Initialize it.

Sign up to request clarification or add additional context in comments.

Comments

0

In any case you have to instantiate lhaservice first before you use it in your (static) constructor:

lhaservice = new XmlDataService.StufServiceSoapClient();

...but unless you show all your relevant code we don't really know for sure what the problem could be in your code.

Note: avoid static classes and operations if they don't make any sense. Make them non-static and create an instance before using the Autoupload operation. Your code will become more flexible and testable. So you might want to rethink your code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.