IAsyncResult & 'Object Reference Not set to an Instance of...'

M

mail.matty

Hi All,

I've been working on a library which does async Http operations. The
library is exposed to COM as I need to access it via SQL2000.

Whenever the following line of code executes it generates the 'Object
Reference...' error.

IAsyncResult result = (IAsyncResult) req.BeginGetResponse(new
AsyncCallback(RespCallback), myRequestState);

something here is causing the error and I can't for the life of me
figure it out. I've included the full code below if anyone wanted to
see this line of code in context. Is the problem how i'm referring to
RespCallBack or myRequestState?

Not looking for an answer, but a nudge in the right direction would be
awsome! I've removed some unrelated code to avoid confusion.

Thanks,

Matt

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Text;
using System.Net;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;




namespace voiceSelectInterface
{

[ InterfaceTypeAttribute( ComInterfaceType.InterfaceIsDual ) ]
public interface IVoiceServer
{

[ DispId( 1000 ) ] int makeCall( string deviceAddress, string
notificationId, string personalCommBit, string messengerBit, string
rollCallBit, string delChanIn, string languageIn, string
databaseConnect );
}


[ ClassInterface( ClassInterfaceType.AutoDual ) ]
public class voiceServer : IVoiceServer
{

public voiceServer ()
{

}

public int makeCall( string deviceAddress, string notificationId,
string personalCommBit, string messengerBit, string rollCallBit, string
delChanIn, string languageIn, string databaseConnect )
{
// ***
// ***
// This function builds and sends the request to intiaite a call on
the Voice Select platform
// The call is initiatied by sending an SSL request to a java
servlet on the Voice Select platform

string connectionString;
string queryStringOne = null;
string queryStringTwo = null;
string queryStringThree = null;
string queryStringMiddle = null;
string queryStringEnd = null;
string queryStringFinal;
string javaServlet = null;
string NPA = null;
string NXX = null;
int localCount = 0;
bool statusBit = false;
int curPorts = 0;

SqlConnection conn = null;
SqlCommand cmd;
SqlDataReader myReader;

queryStringOne = "SELECT vdcAddress FROM tblVoiceDeliveryChannel
WHERE vdcId = ";
queryStringFinal = string.Concat(queryStringOne, delChanIn);

conn = new SqlConnection(databaseConnect);
conn.Open();

cmd = new SqlCommand(queryStringFinal, conn);
cmd.CommandType = CommandType.Text;
myReader = cmd.ExecuteReader();
while (myReader.Read())
{
javaServlet = myReader.GetString(0);
}
myReader.Close();

string javaServlet2 = "&audio.bc.app-parameter-1=";
string javaServlet3 = "&audio.bc.app-parameter-2=";
string javaServlet4 = "&audio.bc.app-parameter-3=";
string javaServlet5 = "&audio.bc.app-parameter-4=";
string javaServlet6 = "&audio.bc.app-parameter-5=";
string javaServlet7 = "&audio.bc.app-parameter-6=";
string fullURI = string.Concat(javaServlet, deviceAddress,
javaServlet2, notificationId, javaServlet3, rollCallBit, javaServlet4,
messengerBit, javaServlet5, personalCommBit, javaServlet6, delChanIn,
javaServlet7, languageIn);

HttpWebRequest req = (HttpWebRequest) WebRequest.Create(fullURI);

//voiceServer myVoiceServer = new voiceServer();
RequestState myRequestState = new RequestState(notificationId,
rollCallBit, messengerBit, personalCommBit, fullURI, delChanIn,
languageIn, databaseConnect);
myRequestState.request = req;

IAsyncResult result = (IAsyncResult) req.BeginGetResponse(new
AsyncCallback(RespCallback), myRequestState);

myRequestState.response.Close();

return 1;
}

public class RequestState
{
// This class stores the State of the request.
const int BUFFER_SIZE = 1024;
public StringBuilder requestData;
public byte[] BufferRead;
public HttpWebRequest request;
public HttpWebResponse response;
public Stream streamResponse;
public string notificationId;
public string rollCallOnOff;
public string messengerOnOff;
public string personalCommOnOff;
public string theUri;
public string delChan;
public string theLanguage;
public string connectionString;

public RequestState(string notificationIn, string rollCallWhich,
string messengerWhich, string personalCommWhich, string uriIn, string
delChanIn, string languageIn, string connectionIn)
{
BufferRead = new byte[BUFFER_SIZE];
requestData = new StringBuilder("");
request = null;
streamResponse = null;
notificationId = notificationIn;
rollCallOnOff = rollCallWhich;
messengerOnOff = messengerWhich;
personalCommOnOff = personalCommWhich;
theUri = uriIn;
delChan = delChanIn;
theLanguage = languageIn;
connectionString = connectionIn;
}
}

private void RespCallback(IAsyncResult asynchronousResult)
{


SqlConnection conn = null;
//string connectionString;
string queryStringOne = null;
string queryStringEnd;
string queryStringMiddle;
string queryStringFinal;
bool statusBit = false;
int curPorts = 0;
return;

}
}

[ ComRegisterFunctionAttribute ]
public static void addExtraRegistrationLogic(string
registrationLogic)
{
// perform any extra logic when registration occurs.
Console.WriteLine( "Invoked by the system since Registration is
occuring ..." );
}

//////////////////////////////////////////////////////
/// <summary>removeExtraRegistrationLogic method</summary>
/// <remarks>
/// This attribute configures this method to be invoked during
/// unregistration of this assembly
/// </remarks>
//////////////////////////////////////////////////////
[ ComUnregisterFunctionAttribute ]
public static void removeExtraRegistrationLogic(string
registrationLogic)
{
// perform any extra logic when unregistration occurs.
Console.WriteLine( "Invoked by the system since Unregistration is
occuring ..." );
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top