相关文章推荐
安静的消炎药  ·  fullcalendar 4.2 使用 ...·  1 年前    · 
爱跑步的篮球  ·  MySQL ...·  1 年前    · 
另类的火柴  ·  [React Native] ...·  1 年前    · 
public partial class MainWindow : Window
        public WeatherReference.WeatherDataServiceClient client = new WeatherReference.WeatherDataServiceClient();
        public IEnumerable<WeatherReference.WeatherDataContract> WeatherDatas
                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

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

Weather applications become very popular in these times:

  • https://learn.microsoft.com/en-us/answers/questions/859235/databindings-are-not-working.html
  • https://learn.microsoft.com/en-us/answers/questions/859211/wcfwpf-can39t-connect-between-those-two-why.html
  • https://learn.microsoft.com/en-us/answers/questions/859604/c-webservice.html
  • https://learn.microsoft.com/en-us/answers/questions/859266/wcf-plus-wpf.html
  • https://learn.microsoft.com/en-us/answers/questions/859301/connect-wpf-with-wcf-using-a-database.html
  • 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.