1
votes

Not really sure why I'm getting the exception.. the code is sound and the API is working through my browser.

var url = new Uri("http://octopart.com/api/search?keywords=" + topic.Text);
        WebClient octopartCall = new WebClient();
        octopartCall.OpenReadCompleted += new OpenReadCompletedEventHandler(Octopart_Completed);
        octopartCall.OpenReadAsync(url);
 if (e.Error == null)
        ... error is not null so I throw the message below  

System.Exception occurred Message=System.Security.SecurityException ---> System.Security.SecurityException: Security error. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.b__4(Object sendState) at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.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.OpenReadAsyncCallback(IAsyncResult result) StackTrace: at Register.Page.Octopart_Completed(Object sender, OpenReadCompletedEventArgs e) InnerException:

2

2 Answers

2
votes

The Visual Studio built in web server can't handle cross domain connections.

Solution 1: make a new virtual directory for your project and run in IIS Solution 2: add crossdomain.xml configuration file to your website project containing

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
     "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>  
    <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
0
votes

Where is error being set? In the Completed handler?

If that's the case, then your problem may be that the handler is not done yet.

Also, you may need to URL encode your URL, since you're adding arbitrary text to it.

Finally, where is this running? ASP.NET? SilverLight? And what versions?