Web services 在silverlight中调用web服务时System.Security.SecurityException

Web services 在silverlight中调用web服务时System.Security.SecurityException,web-services,iis-7,silverlight-4.0,Web Services,Iis 7,Silverlight 4.0,我已经创建了web服务,正在从silverlight应用程序调用 我的内心异常如下: {System.Security.SecurityException-->System.Security.SecurityException:安全错误。 位于System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponseAsyncResult 在System.Net.Browser.BrowserHttpWebRequest.c_DisplayCl

我已经创建了web服务,正在从silverlight应用程序调用

我的内心异常如下:

{System.Security.SecurityException-->System.Security.SecurityException:安全错误。 位于System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponseAsyncResult 在System.Net.Browser.BrowserHttpWebRequest.c_DisplayClassa.b_9对象发送状态 在System.Net.Browser.AsyncHelper.c_DisplayClass4.b_0对象发送状态 -内部异常堆栈跟踪的结束-- 在System.Net.Browser.AsyncHelper.BeginNouisEndorPostCallback beginMethod中,对象状态 位于System.Net.Browser.BrowserHttpWebRequest.EndGetResponseAsyncResult异步结果 在System.Net.WebClient.GetWebResponseWebRequest请求中,IAsyncResult结果 在System.Net.WebClient.downloadsBitsResponseCallbackIAsyncResult结果}

堆栈跟踪:

在System.Net.Browser.AsyncHelper.BeginUnuisisEndorPostCallback beginMethod中,对象状态\r\n在System.Net.Browser.BrowserHttpWebRequest.EndGetResponseAsyncResult异步结果\r\n在System.Net.WebClient.GetWebResponseAsyncResult请求中,IAsyncResult结果\r\n在System.Net.WebClient.DownloadBitsResponseCallbackIAsyncResult结果中

当我搜索此错误时:

我知道这是跨域url的问题,所以我必须在C:\inetpub\wwwroot下添加clientaccesspolicy.xml和crossdomain.xml文件

我仍然得到相同的错误:

让我知道如何修复此错误

下面是我使用过的代码:

            System.Uri uri = new System.Uri("https://[localhost]/CustomerPortalService12/AddAccount/" + "AccountName");


            var result = "";
            try
            {
               var webClient = new WebClient();                  

                    webClient.DownloadStringCompleted +=webClient_DownloadStringCompleted;                     
                    webClient.DownloadStringAsync(uri);                     
            }
            catch (Exception ex)
            {
                var wtf = ex.Message;
            }
        }
    }

       void webClient_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
        {

        }

确保clientaccesspolicy.xml包含您在浏览器中使用的域。如果您在本地调试,这可能是本地主机。clientaccesspolicy.xml必须位于托管服务的域的根目录下。如果您正在托管本地服务以及Silverlight项目,请确保可以从您的bowser访问该文件http://localhost/clientaccesspolicy.xml 或https://localhost/clientaccesspolicy.xml 取决于您呼叫服务的方式。否则,用localhost替换服务所在的域

您的clientaccesspolicy.xml应该如下所示:

<?xml version="1.0" encoding="UTF-8"?>
-<access-policy>
-<cross-domain-access>
<!--May have multiple elements-->
-<policy>
-<allow-from http-request-headers="*">
<domain uri="https://localhost"/>
</allow-from>
-<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>