473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

'Object Reference not set...' with Async

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 ..." );
}
}
}

Nov 17 '05 #1
0 1117

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rodrigo | last post by:
Hi to all: little by little, I'm making my .net app to work. I finally could initiate SQL replication async, using the sqldistrib object, and have the status showed in differents forms. ...
3
by: Matthias Kaeppler | last post by:
Hi, I'm confronted with an error here I haven't encountered before (g++ 3.3.5): Building duality.elf ......
0
by: Passynkov, Vadim | last post by:
I am using Asynchronous Query Processing interface from libpq library. And I got some strange results on Solaris My test select query is 'SELECT * from pg_user;' and I use select system...
6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
1
by: mail.matty | last post by:
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...
4
by: Bill Thorne | last post by:
We have a COM object that has been wrappered for use in .NET and which can make calls which can take a while to execute. These are mainframe integration calls that might perform a lot of data...
3
by: Grant Schenck | last post by:
Hello, I have a Windows Service developed in C# .NET. I'm making it a remote server and I can, via an IPC Channel, expose methods and call them from a client. However, I now want my remoted...
190
by: blangela | last post by:
If you had asked me 5 years ago about the future of C++, I would have told you that its future was assured for many years to come. Recently, I have been starting to wonder. I have been teaching...
0
by: Paul Hadfield | last post by:
Hi, From reading various articles on scalability issues, I understand that there is only a finite number of ASP.NET worker threads and any long running task within ASP.NET should be fired off on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.