1
votes

I have created web service and i am calling from silverlight application.

I am getting Inner Exception like:

{System.Security.SecurityException ---> System.Security.SecurityException: Security error. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClassa.b_9(Object sendState) at System.Net.Browser.AsyncHelper.<>c_DisplayClass4.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 System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result) at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)}

Stack Trace :

" at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)\r\n at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)\r\n at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)"

When I google this error :

I came to know that this is issue of cross domain url so i have to add clientaccesspolicy.xml and crossdomain.xml file under C:\inetpub\wwwroot.

still am getting same error:

Let me know how to fix this error.

Below code i have used:

            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)
        {

        }
1

1 Answers

0
votes

Make sure the clientaccesspolicy.xml contains the domain you are using in the browser. This maybe localhost if you're debugging locally. The clientaccesspolicy.xml must be at the root of the domain where the services is hosted. If you are hosting the service local as well as the Silverlight project then make sure the file is accessible from your bowser at http://localhost/clientaccesspolicy.xml or https://localhost/clientaccesspolicy.xml depending on how you are calling the service. Otherwise substitute localhost for the domain the service is on.

You clientaccesspolicy.xml should look something like:

<?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>