2010-12-13 32 views
1

(Mise à jour)CommunicationException lors de l'appel de service Web Silverlight 4

J'ai construit simple Silverlight 4 Bing Maps application en utilisant le modèle VS2010.

Dans la même solution que j'ai un projet ASP.NET avec un service Web simple: ContentService.asmx. Je cours tous les deux depuis ma machine locale pour l'instant.

je peux appeler le service Web à partir d'une page ASP.NET sans problème.

Cependant, essayez comme je pourrais, je ne peux pas obtenir Silverlight pour parler à lui.

J'essaie d'invoquer le service Web de Silverlight comme suit:

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()); 
} 

Il doit générer le compte de l'objet de liste retournée mais il jette l'exception suivante:

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) 

Je J'ai essayé divers fichiers crossdomain.xml et clientaccesspolicy.xml, rien ne fonctionne.

Toutes les suggestions très appréciées - merci.

Mise à jour

j'ai changé l'adresse de point final à 127.0.0.1 au lieu de localhost et cela a fonctionné!

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

Quelqu'un sait pourquoi?

Répondre

1

Je devine que vous avez ajouté un autre projet Web à votre solution pour héberger ce service WCF? Si c'est le cas, il s'agit probablement d'un problème de domaine croisé dans lequel l'application Silverlight tente de communiquer avec un service sur un autre domaine que celui dont elle provient (même si seul le numéro de port est différent. service dans le projet qui a été créé lorsque vous avez créé l'application Silverlight, et cela va probablement résoudre votre problème.Si vous avez encore des problèmes (ou ce n'était pas le cas), essayez d'utiliser Fiddler pour voir ce qui se passe dans les coulisses. pour obtenir Fiddler pour ramasser le trafic cependant (il ignore le trafic localhost), remplacer les références à localhost dans votre URIs avec ipv4.fiddler.

Hope this helps ...

Chris Anderson

Note: Je n'ai pas vu votre édition avant que je n'aie posté ceci. C'est un drôle!