you will think: "This problem has been solved many, many times. So why doesn't he use Google?" 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.
So here is the problem. There is one Silverlight 4 app and a WCF DataService, both are running on localhost
.
This is the code. Nothing special I guess.
private void InitializeData()
{
var query = (from item in ObjCtx.TestTgt
select item) as DataServiceQuery<TestTgt>;
Debug.Assert(query != null, "'query' is null");
query.BeginExecute(OnLoadDataFinished, query);
}
private void OnLoadDataFinished(IAsyncResult ar)
{
try
{
var query = ar.AsyncState as DataServiceQuery<TestTgt>;
Debug.Assert(query != null, "'query' is null");
var res = query.EndExecute(ar).ToList();
Data.Data = new ObservableCollection<TestTgt>(res);
}
catch(Exception ex)
{
Data.StateDescription = String.Format("Exception occured.{0}{0}{1}", Environment.NewLine, AgExMsgFormatter.GetExText(ex));
}
}
In OnLoadData
at this line: var res = query.EndExecute(ar).ToList();
the following exception occures.
Exception occured.
[EXCEPTION]
[TYPE:] 'InvalidOperationException'
[MESSAGE:] 'An error occurred while processing this request.'
[CALLSTACK:]
at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
at System.Data.Services.Client.QueryResult.EndExecute[TElement](Object source, IAsyncResult asyncResult)
at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, IAsyncResult asyncResult)
at System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)
at SimpleGrid.SimpleGridVm.OnLoadDataFinished(IAsyncResult ar)[INNEREXCEPTION]
[TYPE:] 'SecurityException'
[MESSAGE:] ''
[CALLSTACK:]
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Http.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)[INNEREXCEPTION]
[TYPE:] 'SecurityException'
[MESSAGE:] 'Security error.'
[CALLSTACK:]
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass5.b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.b__0(Object sendState)
[/INNEREXCEPTION]
[/INNEREXCEPTION]
[/EXCEPTION]
As authentication mode I want to use Windows
. Both are configured for this in IIS. The web service is running and is delivering the correct data.
So what am I missing? I thought that this should work. Any help would be appreciated.
Regards
Hmm, ok that's suprising but I got it. The problem is not the authentication or something like this. It's the debugger. The web service is not hosted on the web site of the Silverlight application. So the web service calls are failing.
When loading the deployed site in a browser everything works absolutly fine. For me, it appears somekind of strange, but perhaps someone can give me a good explanation for this behavior.
But this brings up another problem. How do I debug a Silverlight application, when it references an external web service. Perhaps I will open a seperate thread for this.
Regards