Can someone help me? I get a System.ServiceModel.ServiceActivationException: 'Der angeforderte Dienst "http://localhost:58482/WeatherDataService.svc" konnte nicht aktiviert werden Exception, but I don't find the problem.

Teufel Larissa18 26 Reputation points
2022-05-23T10:29:18.373+00:00

MainWindow.xml.cs

public partial class MainWindow : Window
    {
        public WeatherReference.WeatherDataServiceClient client = new WeatherReference.WeatherDataServiceClient();
        public IEnumerable<WeatherReference.WeatherDataContract> WeatherDatas
        {
            get
            {
                return client.GetData(fromDate.SelectedDate ?? DateTime.MinValue, toDate.SelectedDate ?? DateTime.MaxValue);
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
        }

        private void SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            weatherDataGrid.ItemsSource = WeatherDatas;
        }

        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            IEnumerable<WeatherReference.WeatherDataContract> temp = client.GetData(fromDate.SelectedDate ?? DateTime.MinValue, toDate.SelectedDate ?? DateTime.MaxValue);
            foreach (WeatherReference.WeatherDataContract w in temp)
            {
                foreach (DataGridRow row in weatherDataGrid.SelectedItems)
                {

                    if (w.Id == ((WeatherReference.WeatherDataContract)row.Item).Id)
                    {

                    }
                }
            }
        }
    }

MainWindow.xaml

<Grid>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Height="39" VerticalAlignment="Top">
            <Label Content="From:" Width="74" VerticalAlignment="Center"/>
            <DatePicker x:Name="fromDate" Width="155" SelectedDateChanged="SelectedDateChanged" />
            <Label Content="To:" Width="74" VerticalAlignment="Center"/>
            <DatePicker x:Name="toDate" Width="155" SelectedDateChanged="SelectedDateChanged"/>
        </StackPanel>
        <DataGrid ItemsSource="{Binding WeatherDatas}" x:Name="weatherDataGrid" Height="284" Margin="35,44,35,0" VerticalAlignment="Top" AutoGenerateColumns="True"/>
        <Button x:Name="Delete" Content="Delete" HorizontalAlignment="Left" Margin="35,353,0,0" VerticalAlignment="Top" Width="100" Height="32" Click="Delete_Click"/>
    </Grid>

Service

    public class WeatherDataService : IWeatherDataService
        {
            //private const int responseSize = 100;
            public IEnumerable<WeatherDataContract> GetData(DateTime fromDate, DateTime toDate)
            {
                WeatherDataEntities entities = new WeatherDataEntities();
                entities.WeatherDatas.Add(new WeatherData()
                {
                    Id = 100000
                });
                entities.SaveChanges();

                return (from w in entities.WeatherDatas
                        where w.Datum >= fromDate && w.Datum <= toDate
                        select new WeatherDataContract()
                        {
                            Id = w.Id,
                            Datum = (DateTime)w.Datum,
                            Zeit = (TimeSpan)w.Zeit,
                            Temperatur = (double)w.Temperatur,
                            Luftdruck = (int)w.Luftdruck,
                            Regen = (int)w.Regen,
                            Wind = (double)w.Wind,
                            Richtung = (int)w.Richtung,
                            Feuchtigkeit = (int)w.Feuchtigkeit
                        }).Take(100).ToList();

            }

            public void deleteData(WeatherDataContract weather)
            {
     client.deleteData(new WeatherReference.WeatherDataContract() { Id = w.Id});
            }

[ServiceContract]
    public interface IWeatherDataService
    {
        [OperationContract]
        IEnumerable<WeatherDataContract> GetData(DateTime fromDate, DateTime toDate);
        [OperationContract]
        void deleteData(WeatherDataContract weather);
    }

IService

// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class WeatherDataContract
{
    [DataMember]
    public int Id { get; set; }
    [DataMember]
    public DateTime Datum { get; set; }
    [DataMember]
    public TimeSpan Zeit { get; set; }
    [DataMember]
    public double Temperatur { get; set; }
    [DataMember]
    public int Luftdruck { get; set; }
    [DataMember]
    public int Regen { get; set; }
    [DataMember]
    public double Wind { get; set; }
    [DataMember]
    public int Richtung { get; set; }
    [DataMember]
    public int Feuchtigkeit { get; set; }
}
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,367 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,471 Reputation points Microsoft Vendor
    2022-05-24T07:15:23.483+00:00

    Hi @Teufel Larissa18 ,
    You can configure traces to view the server's diagnostic trace logs to find specific problems.
    You can check the documentation for specific steps.
    https://learn.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing?redirectedfrom=MSDN
    You can also try opening a browser and entering the service URI, usually you can get the error message you need from this screen.

    This error may be caused by insufficient server memory, you can try restarting the computer (not recommended), or you can try adding <serviceHostingEnvironment minFreeMemoryPercentageToActivateService="1"> in <system.serviceModel>
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments