Hi All,
I've hit a stumbling block and haven't been able to get past it yet.
What I'm trying to do is create a library which makes Http Requests to
a java servlet at the same time and then processes the response(s) when
returned. I've got the following code written which generates the
infamous 'Object Reference Not Set to an Instance of an Object error'.
The error lies in this line of code (I've marked it with a ******
******) in the full code body attached below.
Offending code:
IAsyncResult result = (IAsyncResult) req.BeginGetResponse(new
AsyncCallback(RespCallback), myRequestState);
I think the problem has something to do with how I'm referencing the
callback function, but to be honest I'm not really sure.
If someone could just give me a little nudge in the right direction I
would be forever grateful.
NOTE: I've removed superflourus code below for simplicity's sake.
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;
******* This is where the problem lies ******* IAsyncResult result
= (IAsyncResult) req.BeginGetResponse(new AsyncCallback(RespCallback),
myRequestState);
myRequestState.response.Close();
}
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;
}
}
[ 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 ..." );
}
}
}