Failed to Invoke:CallOpen error calling WebService from Silverligh


B

Bob

I have built an ASP.NET Web Service from an existing database in SQL Server
2008 using the Entity Framework model. This works fine and the service can be
viewed as expected from Internet Explorer. One of the tables in the db is a
Customers collection. I have placed ClientAccessPolicy and CrossDomainPolicy
files in the root of the site. The site is running at
http://localhost:1111/LiveTrackerService.svc.

I now build a Silverlight app in a separate solution and can add a service
reference to the service OK.

I try to access the Customers table with the code shown below. This fails
with the error "Failed to Invoke:callOpen" at the line atcq.BeginExecute.

In the commented out section of the code I try to call the service via the
DownloadStringAsync method. This fails with
System.Reflection.TargetInvocationError.

It doesn't seem to be a cross domain issue. Web Development Helper shows the
CAP file being found OK.

Any help will be greatly appreciated.


void Page_Loaded(object sender, RoutedEventArgs e)
{
LiveTrackerData.TrackingEntities proxy =
new LiveTracker.LiveTrackerData.TrackingEntities(new
Uri("http://localhost:1111/LiveTrackerData.svc", UriKind.Absolute));

var customers = from c in proxy.Customer
select c;
var atcq =
(DataServiceQuery<Customer>)customers;
atcq.BeginExecute(new AsyncCallback(OnLoadComplete), atcq);
//WebClient restClient = new WebClient();
//restClient.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(restClient_DownloadStringCompleted);
//restClient.DownloadStringAsync(new
Uri("http://localhost:1111/LiveTrackerData.svc/Customer",
UriKind.RelativeOrAbsolute));
}

void restClient_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
string test = e.Result;
}

void OnLoadComplete(IAsyncResult result)
{
DataServiceQuery<Customer> trackerQuery =
(DataServiceQuery<Customer>)result.AsyncState;
try
{
List<Customer> trackers =
trackerQuery.EndExecute(result).ToList();
foreach (Customer atc in trackers)
{
ListBoxItem item = new ListBoxItem();
item.Content = atc.CustomerName;
TrackerList.Items.Add(item);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
;

}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top