|
Hi, I'm working on a intranet solution. I'm trying to call asynchronously a web service on the same server and virtual directory of the aspx page (the one that generates the html with the <object ...> tag). The smart client actually gets a dataset from the webservice and displays it on a datagrid. With the sync version everything works fine. With the async when I use Invoke to set the dataset: public void getSessionDSCallback(IAsyncResult ar) { Trace.WriteLine("inizio getSessionDSCallback"); ds = new DataSet(); it.creval.WPEX.Includes.ControlliBrowser.WPEX.Net.ListaAssegni pf = (it.creval.WPEX.Includes.ControlliBrowser.WPEX.Net.ListaAssegni) ar.AsyncState; pf.Credentials = CredentialCache.DefaultCredentials; // Get the completed results. ds = pf.EndgetSessionDS(ar); DataBindToDataGridMethodDelegate CallDataBindToDataGrid = new DataBindToDataGridMethodDelegate(this.DataBindToDataGrid); Object[] newArgs = new Object[1]; newArgs[0] = ds; Trace.WriteLine("invoke"); try { Invoke(CallDataBindToDataGrid, newArgs); } catch (Exception anException) { Trace.WriteLine("getSessionDSCallback " + anException.Message + anException.StackTrace); } Trace.WriteLine("fine getSessionDSCallback"); } I get [964] inizio getSessionDSCallback [964] invoke [964] getSessionDSCallback Request for the permission of type System.Security.Permissions.SecurityPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed. at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet grantedSet, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permToken) [964] at System.Security.CodeAccessSecurityEngine.Check(PermissionToken permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32 unrestrictedOverride) [964] at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) [964] at System.Security.CodeAccessPermission.Demand() [964] at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) [964] at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) [964] at it.creval.WPEX.Includes.ControlliBrowser.SessionDataGrid.getSessionDSCallback(IAsyncResult ar) [964] fine getSessionDSCallback
This problem is caused by the different thread were the getSessionDSCallback method is called. The call to invoke use some unmanaged code. When I give "Allow calls to unmanaged assemblies" to all_code the smart client is working fine. Does someone if there's a way to give this policy only to a subset of code?
Thanks in advance for any help. Carlo |