title: SL 4 and WCF DataService: InvalidOperationException -> SecurityException
body: <p>you will think: &quot;This problem has been solved many, many times. So why doesn't he use Google?&quot; Please, believe me, I tried everything. I'm dealing with this problem since last week. I read many blogs and searched the MSDN. But I don't get it.</p>
  <p>So here is the problem. There is one Silverlight 4 app and a WCF DataService, both are running on <code>localhost</code>.</p>
  <p>This is the code. Nothing special I guess.</p>
  <pre><code>     private void InitializeData()
          {
              var query = (from item in ObjCtx.TestTgt
                               select item) as DataServiceQuery&lt;TestTgt&gt;;
              Debug.Assert(query != null, "'query' is null");
  
              query.BeginExecute(OnLoadDataFinished, query);
          }
  
          private void OnLoadDataFinished(IAsyncResult ar)
          {
              try
              {
                  var query = ar.AsyncState as DataServiceQuery&lt;TestTgt&gt;;
                  Debug.Assert(query != null, "'query' is null");
  
                  var res = query.EndExecute(ar).ToList();
                  Data.Data = new ObservableCollection&lt;TestTgt&gt;(res);
              }
              catch(Exception ex)
              {
                  Data.StateDescription = String.Format("Exception occured.{0}{0}{1}", Environment.NewLine, AgExMsgFormatter.GetExText(ex));
              }
          }
  </code></pre>
  <p>In <code>OnLoadData</code> at this line: <code>var res = query.EndExecute(ar).ToList();</code> the following exception occures.</p>
  <blockquote>
  <p>Exception occured.</p>
  <p>[EXCEPTION]<br>
  [TYPE:]       'InvalidOperationException'<br>
  [MESSAGE:]    'An error occurred while processing this request.'<br>
  [CALLSTACK:] <br>
  at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)<br>
  at System.Data.Services.Client.QueryResult.EndExecute[TElement](Object source, IAsyncResult asyncResult)<br>
  at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, IAsyncResult asyncResult)<br>
  at System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)<br>
  at SimpleGrid.SimpleGridVm.OnLoadDataFinished(IAsyncResult ar)<br><br></p>
  <p>[INNEREXCEPTION]<br>
  [TYPE:]       'SecurityException'<br>
  [MESSAGE:]    ''<br>
  [CALLSTACK:] <br>
  at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)<br>
  at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)<br>
  at System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)<br>
  at System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)<br><br></p>
  <p>[INNEREXCEPTION]<br>
  [TYPE:]       'SecurityException'<br>
  [MESSAGE:]    'Security error.'<br>
  [CALLSTACK:] <br>
  at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)<br>
  at System.Net.Browser.ClientHttpWebRequest.&lt;&gt;c__DisplayClass5.b__4(Object sendState)<br>
  at System.Net.Browser.AsyncHelper.&lt;&gt;c__DisplayClass2.b__0(Object sendState)<br>
  [/INNEREXCEPTION]<br>
  [/INNEREXCEPTION]<br>
  [/EXCEPTION]</p>
  </blockquote>
  <p>As authentication mode I want to use <code>Windows</code>. Both are configured for this in IIS. The web service is running and is delivering the correct data.</p>
  <p>So what am I missing? I thought that this should work. Any help would be appreciated.</p>
  <p>Regards</p>