Error Service Reference WCF/WPF/ASP.NET

Anonymous
2022-09-12T21:26:26.493+00:00

Hello, i have got a problem. Somehow my ServiceReference is not working for my ASP.net application, but for my WPF application its working fine. Does anyone have a clue what the problem could be? Thank you in advance! ![240177-project.png][1] [240237-code.txt][2] WCF IService1 [ServiceContract] public interface IService1 [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); [OperationContract] IEnumerable<SalesDTO> GetAllSales(); [OperationContract] IEnumerable<StoresDTO> GetAllStores(); [OperationContract] IEnumerable<TitlesDTO> GetAllTitles(); [OperationContract] IEnumerable<CompleteTitlesDTO> GetTitlesByType(string type); [OperationContract] IEnumerable<string> GetAllTypes(); [OperationContract] void UpdateSales(SalesDTO dto); // TODO: Hier Dienstvorgänge hinzufügen } DTOs public class SalesDTO { public string OrderNum { get; set; } public DateTime OrderDate { get; set; } public short Quantity { get; set; } public string PaymentTerms { get; set; } public StoresDTO Store { get; set; } public TitlesDTO Title { get; set; } } public class StoresDTO { public string StoreName { get; set; } public string StoreId { get; set; } } public class TitlesDTO { public string Title { get; set; } public string TitleId { get; set; } } public class CompleteTitlesDTO { public decimal? Advance { get; set; } public string Notes { get; set; } public decimal? Price { get; set; } public DateTime PubDate { get; set; } public string Publisher { get; set; } public int? Royalty { get; set; } public string Title { get; set; } public string TitleId { get; set; } public string Type { get; set; } public int? YdtSales { get; set; } } public partial class titles { public titles() { this.sales = new HashSet<sales>(); this.titleauthor = new HashSet<titleauthor>(); } public string title_id { get; set; } public string title { get; set; } public string type { get; set; } public string pub_id { get; set; } public Nullable<decimal> price { get; set; } public Nullable<decimal> advance { get; set; } public Nullable<int> royalty { get; set; } public Nullable<int> ytd_sales { get; set; } public string notes { get; set; } public System.DateTime pubdate { get; set; } public virtual publishers publishers { get; set; } public virtual ICollection<sales> sales { get; set; } public virtual ICollection<titleauthor> titleauthor { get; set; } public virtual roysched roysched { get; set; } Service1 public class Service1 : IService1 { public IEnumerable<SalesDTO> GetAllSales() { pubsEntities pubs = new pubsEntities(); var quere = from sale in pubs.sales select new SalesDTO { OrderNum = sale.ord_num, OrderDate = sale.ord_date, Quantity = sale.qty, PaymentTerms = sale.payterms, Store = new StoresDTO { StoreName = sale.stores.stor_name, StoreId = sale.stores.stor_id }, Title = new TitlesDTO { Title = sale.titles.title, TitleId = sale.titles.title_id } }; return quere; } public IEnumerable<StoresDTO> GetAllStores() { pubsEntities pubs = new pubsEntities(); var quere = from store in pubs.stores select new StoresDTO { StoreName = store.stor_name, StoreId = store.stor_id }; return quere; } public IEnumerable<TitlesDTO> GetAllTitles() { pubsEntities pubs = new pubsEntities(); var quere = from title in pubs.titles select new TitlesDTO { Title = title.title, TitleId = title.title_id }; return quere; } public IEnumerable<string> GetAllTypes() { pubsEntities pubs = new pubsEntities(); var quere = from title in pubs.titles select title.type; return quere; } public string GetData(int value) { return string.Format("You entered: {0}", value); } public CompositeType GetDataUsingDataContract(CompositeType composite) { if (composite == null) { throw new ArgumentNullException("composite"); } if (composite.BoolValue) { composite.StringValue += "Suffix"; } return composite; } public IEnumerable<CompleteTitlesDTO> GetTitlesByType(string type) { pubsEntities pubs = new pubsEntities(); var quere = from title in pubs.titles where title.type.Equals(type) select new CompleteTitlesDTO { Advance = title.advance, Notes = title.notes, Price = title.price, PubDate = title.pubdate, Publisher = title.publishers.pub_name, Royalty = title.royalty, Title = title.title, TitleId = title.title_id, Type = title.type, YdtSales = title.ytd_sales }; return quere; } public void UpdateSales(SalesDTO dto) { pubsEntities pubs = new pubsEntities(); bool gefunden = false; foreach(sales sale in pubs.sales) { if(sale.ord_num.Equals(dto.OrderNum) && sale.stor_id.Equals(dto.Store.StoreId) && sale.title_id.Equals(dto.Title.TitleId)) { sale.ord_date = dto.OrderDate; sale.payterms = dto.PaymentTerms; sale.qty = dto.Quantity; gefunden = true; break; } } if (!gefunden) { sales sale = new sales { ord_date = dto.OrderDate, payterms = dto.PaymentTerms, qty = dto.Quantity, ord_num = dto.OrderNum, title_id = dto.Title.TitleId, stor_id = dto.Store.StoreId }; pubs.sales.Add(sale); } pubs.SaveChanges(); } } WPF <Window x:Class="WpfApp10.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp10" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Window.Resources> <CollectionViewSource x:Key="Stores" Source="{Binding Stores}"/> <CollectionViewSource x:Key="Titles" Source="{Binding Titles}"/> </Window.Resources> <Grid> <DataGrid x:Name="datagrid1" Margin="10,10,10,10" RowEditEnding="datagrid1_RowEditEnding"> <DataGrid.Columns> <DataGridTextColumn Header="Order Number" Binding="{Binding OrderNum, UpdateSourceTrigger=PropertyChanged}" /> <DataGridComboBoxColumn Header="Title" ItemsSource="{Binding Source={ StaticResource Titles}}" DisplayMemberPath="Title" SelectedValuePath=" TitleId" SelectedItemBinding="{Binding Title.Title}" SelectedValueBinding="{Binding Title.TitleId}" /> <DataGridComboBoxColumn Header="Store" ItemsSource="{Binding Source={ StaticResource Stores}}" DisplayMemberPath="StoreName" SelectedValuePath="StoreId" SelectedItemBinding="{Binding Store. StoreName}" SelectedValueBinding="{Binding Store.StoreId}" /> <DataGridTemplateColumn Header="OrderDate"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <DatePicker SelectedDate="{Binding OrderDate}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <DatePicker SelectedDate="{Binding OrderDate}" /> </DataTemplate> </DataGridTemplateColumn.CellEditingTemplate> </DataGridTemplateColumn> <DataGridTextColumn Header="Quantity" Binding="{Binding Quantity, UpdateSourceTrigger=PropertyChanged}" /> <DataGridTextColumn Header="Payment Terms" Binding="{Binding PaymentTerms , UpdateSourceTrigger=PropertyChanged}" /> </DataGrid.Columns> </DataGrid> </Grid> </Window> public partial class MainWindow : Window { ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(); public IEnumerable<ServiceReference1.StoresDTO> Stores { get; set; } public IEnumerable<ServiceReference1.TitlesDTO> Titles { get; set; } bool handle; public MainWindow() { InitializeComponent(); DataContext = this; Stores = client.GetAllStores(); Titles = client.GetAllTitles(); datagrid1.ItemsSource = client.GetAllSales(); handle = true; } private void datagrid1_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { if (handle) { handle = false; datagrid1.CommitEdit(); ServiceReference1.SalesDTO dto = e.Row.Item as ServiceReference1.SalesDTO; client.UpdateSales(dto); datagrid1.ItemsSource = client.GetAllSales(); handle = true; } } } ASP.NET <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Anzeigetafel.aspx.cs" Inherits="Anzeigetafel" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem Text="Bitte wählen" Value=""></asp:ListItem> </asp:DropDownList> </div> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </form> </body> </html> public partial class Anzeigetafel : System.Web.UI.Page { ServiceReference1.Service1Client client; bool dropDownFuellen = true; protected void Page_Load(object sender, EventArgs e) { client = new ServiceReference1.Service1Client(); if (dropDownFuellen) { foreach(string type in client.GetAllTypes()) { DropDownList1.Items.Add(type); } } dropDownFuellen = false; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { GridView1.DataSource = client.GetTitlesByType(DropDownList1.SelectedValue); GridView1.DataBind(); } } [1]: /api/attachments/240177-project.png?platform=QnA [2]: /api/attachments/240237-code.txt?platform=QnA

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,798 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.