views:

24

answers:

1

I am trying to send data on the server using the following code in windows 7 phone based development.

public static void sendData()
{
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
    IAsyncResult token = request.BeginGetResponse(new AsyncCallback(GetStatusesCallBack), request);
}

public static void GetStatusesCallBack(IAsyncResult result)
{
    WebResponse response = ((HttpWebRequest)result.AsyncState).EndGetResponse(result); 
    StreamReader reader = new StreamReader(response.GetResponseStream());
    string responseString = reader.ReadToEnd(); reader.Close();            
}

Problem is that when I call sendData method, it does not call the callback function GetStatusesCallBack. When i tried to check token object, It contained following entry

'token.AsyncWaitHandle' threw and exception of type 'System.NotSupportedException'

Can anyone please tell me how to fix it?

Best Regards

A: 

You can't create an instance of an interface. This is why you are getting the error.

For simplicity, do the following to let the compiler determine what token should be:

var token = request.BeginGetResponse(new AsyncCallback(GetStatusesCallBack), request);

Or, as you aren't using token for anything, you could just not bother assigning the result of 'BeginGetResponse to anything:

request.BeginGetResponse(new AsyncCallback(GetStatusesCallBack), request);
Matt Lacey