1
votes

(Updated)

I've built a simple Silverlight 4 Bing Maps app using the VS2010 template.

Within the same solution I've got an ASP.NET project with a simple Web Service: ContentService.asmx.

I'm running both from my local machine for now.

I can invoke the Web Service from within an ASP.NET page with no problems.

However, try as I might, I can't get Silverlight to talk to it.

I try to invoke the Web Service from Silverlight as follows:

public BingMapAppPanel()
{
    InitializeComponent();

    BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);

    EndpointAddress endPoint = new EndpointAddress("http://localhost:49501/ContentService.asmx");

    ContentServiceSoapClient contentService = new ContentServiceSoapClient(binding, endPoint);

    contentService.GetAllCategoriesCompleted += new EventHandler<GetAllCategoriesCompletedEventArgs>(contentService_GetAllCategoriesCompleted);
    contentService.GetAllCategoriesAsync();
}

void contentService_GetAllCategoriesCompleted(object sender, GetAllCategoriesCompletedEventArgs e)
{    
    MessageBox.Show(e.Result.Count.ToString());
}

It should output the count of the returned List object but instead it throws the following exception:

Bing Maps has encountered an exception. Please press CTRL+C to copy the error message text.

ErrorSource: Unhandled Exception.

ErrorType:  System.Reflection.TargetInvocationException

ErrorMessage:  An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.

ErrorCallStack:
   at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()

   at BingMapApp.Content.GetAllCategoriesCompletedEventArgs.get_Result()

   at BingMapApp.BingMapAppPanel.contentService_GetAllCategoriesCompleted(Object sender, GetAllCategoriesCompletedEventArgs e)

   at BingMapApp.Content.ContentServiceSoapClient.OnGetAllCategoriesCompleted(Object state)

InnerType:  System.ServiceModel.CommunicationException

InnerMessage:  

InnerCallStack:
   at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)

   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)

   at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)

   at BingMapApp.Content.ContentServiceSoapClient.ContentServiceSoapClientChannel.EndGetAllCategories(IAsyncResult result)

   at BingMapApp.Content.ContentServiceSoapClient.BingMapApp.Content.ContentServiceSoap.EndGetAllCategories(IAsyncResult result)

   at BingMapApp.Content.ContentServiceSoapClient.EndGetAllCategories(IAsyncResult result)

   at BingMapApp.Content.ContentServiceSoapClient.OnEndGetAllCategories(IAsyncResult result)

   at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)

I've tried various crossdomain.xml and clientaccesspolicy.xml files, nothing works.

Any suggestions much appreciated - thanks.

Update

I changed the endpoint address to 127.0.0.1 instead of localhost and it worked!

EndpointAddress endPoint = new EndpointAddress("http://127.0.0.1:49501/ContentService.asmx");

Anyone know why?

1

1 Answers

1
votes

I'm guessing you've added another Web project to your solution to host this WCF service? If so, it most likely is a cross domain issue, where the Silverlight application is attempting to communicate with a service on another domain than the one from which it originated (even though it's only the port number that differs. If possible, host the WCF service in the project that was created when you created the Silverlight application, and this will likely solve your problem. If you're still having trouble (or this wasn't the case), try using Fiddler to see what's happening behind the scenes. To get Fiddler to pick up the traffic however (it ignores localhost traffic), replace references to localhost in your URIs with ipv4.fiddler.

Hope this helps...

Chris Anderson

Note: I didn't see your edit before I posted this. That's a weird one!