Problem
I have a quiet web service running on a remote server. I already made a WP7 application that uses it, so I know that it works. I am porting an application to a Silverlight web application and have encountered a problem.
I included a simplified version of the code, as well as the error that was selected. The error is called by the EndGetResponse
method.
Feel free to request more information. I have a search around solutions and have not found anything that works or really relates to my problem. It seems like such simple code, and it works great on the WP7 version. Any help would be appreciated.
Code
void SendRequest() { string url = "http://some-example-restful-service:5600/locations/data/all"; HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json; charset=utf-8"; request.BeginGetResponse(new AsyncCallback(RequestCallback), request); } public static void RequestCallback(IAsyncResult asyncResult) { HttpWebRequest request = (HttpWebRequest) asyncResult.AsyncState; HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(asyncResult);
Error
SecurityException failed to execute user code
System.Security.SecurityException: Security Error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState) at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at ServieTest.MainPage.RequestCallback(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassd.<InvokeGetResponseCallback>b__b(Object state2) at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
source share