'System.NullReferenceException' when call a Web Service

Hi, there

I Invoke Web Service, it's fine. 


********Code Here**************************** 

CalcWebService calc = new CalcWebService(); 

AsyncCallback cb = new AsyncCallback(GetAddCompleted); 
IAsyncResult res = calc.BeginAdd(2, 2, cb, null); 

private void GetAddCompleted(IAsyncResult res) 

int sum = calc.EndAdd(res); 


********Code Here**************************** 


The return value is correct, it's great. 
But a few minutes later, 
I got an error 'System.NullReferenceException' 

at System.Net.OSSOCK.WSAGetOverlappedResult(IntPtr socketHandle, IntPtr overlapped, 
UInt32& bytesTransferred, Boolean wait, IntPtr ignored)
at System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, 
UInt32 numBytes, NativeOverlapped* nativeOverlapped)'[4496] 

Why  All things are right, why got the error message  

Need your help, Thanks...


Answer this question

'System.NullReferenceException' when call a Web Service

  • C_wander

    I was just proposing a stylistic change, based on previous experience. I've never seen this error, and have idea what's causing it. Perhaps someone else has seen it...
  • ddaSedN

    Thanks a lot for your reply,

    but I got the same error message a few minutes later when return the correct value.

    Oh, how can I do

    Thanks...

  • Conrad Rowlands

    Hi,

    I try a very easy example "HelloWord",
    only a Label and a Button on Client App

    private void button1_Click(object sender, System.EventArgs e)
    {
        Service1 service = new Service1();
        label1.Text = service.HelloWorld();
    }

    oops! the result is the same, I can get the "HelloWord" string, 
    but about ten minutes later, 
    I got 'System.NullReferenceException' again.

    I don't know how can I do.
    Do you try it for me  Please...

    http://doraemon.europe.webmatrixhosting.net/Service1.asmx

    Thanks...

  • Amjad

    I've always been a bit nervous about using "global" references to Web Services, You might try passing the service object to the callback directly, like this:

    public void Test()
    {
      CalcWebService calc = new CalcWebService(); 

      AsyncCallback cb = new AsyncCallback(GetAddCompleted); 
      IAsyncResult res = calc.BeginAdd(2, 2, cb, calc); 
    }

    private void GetAddCompleted(IAsyncResult res) 

      CalcWebService calc = (CalcWebService) res.AsyncState;
      int sum = calc.EndAdd(res); 
    }

    and see if it changes anything.

  • Jayapal Chandran


    I find out the problem, 
    if run Client App in Visual Studio .NET 2003 IDE, 
    will get the 'System.NullReferenceException' 

    if run without IDE, it works well. 

    Thanks... 

  • Steveloc

    I run the

    http://support.microsoft.com/default.aspx scid=kb;en-us;Q320438
    Webservicessamples.exe,

    and happen the same thing.

    The return value is correct, a few minutes later, 
    got an error 'System.NullReferenceException'

    *******Error Message***********************************************************

    at System.Net.OSSOCK.WSAGetOverlappedResult(IntPtr socketHandle, IntPtr overlapped, 
    UInt32& bytesTransferred, Boolean wait, IntPtr ignored) 
    at System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, 
    UInt32 numBytes, NativeOverlapped* nativeOverlapped)'[4496] 

    *******Error Message***********************************************************

    So, my code is right, because the Webservicessamples.exe also got the same message,
    but, I cann't find where the problem is, is my server wrong 
    I had put it on internet web-hosting, it also happened.

    Need your help, thanks...

  • Yury Averkiev

    Well, I tried it in the IDE, and let it sit for half an hour without incident. I have to believe that something is configured incorrectly on your system, because the behavior you're seeing is not normal, and should not occur. 
  • MaqsoodAhmed

    I have exactly the same error while trying to achieve async tcp/ip socket by using threadpool for the listen thread and delegate.

    so are you suggesting that it can only be ran on machine without the IDE installed

    any comments are greatly appreciated.

    I got:

    Nullreference blar blar blar

    at Form1.ReceiveCallBack(IAsyncResult ar)
    at OverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes,

    NativeOverlapped* nativeOverlapped)



  • 'System.NullReferenceException' when call a Web Service