(aktualisiert)Communication, wenn Web-Service von Silverlight 4
Aufruf habe ich eine einfache Silverlight 4 Bing Maps App mit dem VS2010 Vorlage erstellt.
Innerhalb der gleichen Lösung, die ich ein ASP.NET-Projekt mit einem einfachen Web-Service habe: ContentService.asmx.
Ich laufe jetzt von meinem lokalen Rechner beides.
kann ich die Web-Service aus einer ASP.NET-Seite ohne Probleme aufrufen.
jedoch versuchen, wie ich könnte, kann ich nicht bekommen Silverlight, um es zu sprechen.
Ich versuche, die Web-Service von Silverlight aufrufen wie folgt:
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());
}
Es ausgeben sollte die Zählung des Objekts zurückgegeben Liste, sondern wirft es die folgende Ausnahme:
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‘ Habe verschiedene crossdomain.xml und clientaccesspolicy.xml Dateien ausprobiert, nichts funktioniert.
Alle Vorschläge sehr geschätzt - danke.
aktualisieren
änderte ich den Endpunkt-Adresse anstelle von localhost 127.0.0.1 und es funktionierte!
EndpointAddress endPoint = new EndpointAddress ("http://127.0.0.1:49501/ContentService.asmx");
Wer weiß warum?