OK, so I have no idea why this isn’t working. I’ve found 4 different tutorials/examples of calling a JSON web service asynchronously within Silverlight, and all of them use the same format / logic as I am. On the line “using (streamCommunities = request.EndGetRequestStream(asyncResult))” it is throwing the error I attached at the bottom, an ArgumentException saying it doesn’t like the asyncResult. Why is this if every other example I’ve found uses the same logic?
private void GetSource(object state)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(MyValidUri));
request.Method = "POST";
request.ContentType = "application/json";
request.BeginGetResponse(new AsyncCallback(ReadCommunityCallBack), request);
}
private void ReadCommunityCallBack(IAsyncResult asyncResult)
{
HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
using (Stream outStream = request.EndGetRequestStream(asyncResult))
{
// DO STUFF HERE
}
}
And the error is here:
System.ArgumentException was unhandled by user code
Message=Value does not fall within the expected range.
StackTrace:
at System.Net.Browser.ClientHttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult)
at cenTabbedFeed.MainPage.ReadCommunityCallBack(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass1a.<InvokeGetResponseCallback>b__18(Object state2)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Like I said, I’ve been scouring examples and trying to find an answer on MSDN and I’m stuck and frustrated.
-Thanks in advance
RJ
your request method is
POSTbut you don’t post anything. Either write something to RequestStream or change your method toGET.–EDIT–
You can post some string to server as below