question

iamthecode-3146 avatar image
0 Votes"
iamthecode-3146 asked llaxmikant commented

Why isn't my WCF/WPF service working?

This is my structure and what I did:



WCF

add Entity Framework

IService

add [OperationContract] in IService1
create DTO classes for things I needed

Service

in Service1 create class variable "Entity entity= new Entity()"
used LINQ to geht the stuff i needed, e.g.:

         var list = from sale in pubs.sales
                    select new SalesDTO
                    {
                        OrderDate = sale.ord_date,
                        OrderNum = sale.ord_num,
                        Quantity = sale.qty,
                        PaymentTerms = sale.payterms,
                        Title = new TitlesDTO
                        {
                            Title = sale.titles.title,
                            TitleId = sale.titles.title_id
                        },
                        Store = new StoresDTO
                        {
                            StoreName = sale.stores.stor_name,
                            StoreId = sale.stores.stor_id
                        }
                    };

updated some data:

     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.title_id.Equals(dto.Title.TitleId) && sale.stor_id.Equals(dto.Store.StoreId))
             {
                 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,
                 ord_num = dto.OrderNum,
                 payterms = dto.PaymentTerms,
                 qty = dto.Quantity,
                 title_id = dto.Title.TitleId,
                 stor_id = dto.Store.StoreId
             };
             pubs.sales.Add(sale);
         }

         pubs.SaveChanges();
     }

DataGrid

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


WPF

create Connected Service (rightclick WPF, add, Connected Service)

MainWindow.xaml.cs

add "ServiceReference2.Service1Client client = new ServiceReference2.Service1Client();"


     public MainWindow()
     {
         InitializeComponent();
         DataContext = this;
         datagrid.ItemsSource = client.GetAllSales();
         Stores = client.GetAllStores();
         Titles = client.GetAllTitles();
         handle = true;
     }

     private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
     {
         if (handle)
         {
             handle = false;
             datagrid.CommitEdit();
             ServiceReference2.SalesDTO dto = e.Row.DataContext as ServiceReference2.SalesDTO;
             client.UpdateSales(dto);
             handle = true;
             datagrid.ItemsSource = client.GetAllSales();
         }
     }

ASP.NET

new Project, "ASP:NET Web Application"
don't write code into "Default.aspx", write it into "Defaultaspx.cs"
in "Default.aspx" use on the left "Toolbox" for needed tools

ASP Events

<asp:DropDownList runat="server" id="GreetList" autopostback="true">
<asp:ListItem value="no one">No one</asp:ListItem>
<asp:ListItem value="world">World</asp:ListItem>
<asp:ListItem value="universe">Universe</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList runat="server" id="GreetList" autopostback="true" onselectedindexchanged="GreetList_SelectedIndexChanged">

Code behind

protected void GreetList_SelectedIndexChanged(object sender, EventArgs e)
{
HelloWorldLabel.Text = "Hello, " + GreetList.SelectedValue;
}


WIndows Auth

using Microsoft.AspNetCore.Authentication.Negotiate;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();

builder.Services.AddAuthorization(options =>
{
options.FallbackPolicy = options.DefaultPolicy;
});
builder.Services.AddRazorPages();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.MapRazorPages();

app.Run();



windows-wpfdotnet-aspnet-generaldotnet-entity-framework-corewindows-wcf
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@iamthecode-3146 . Welcome Microsoft Q&A.
Is there an error when the service is not working? If so, could you show the error details?

0 Votes 0 ·

have you tried testing your WCF service using WCFTestClient?

0 Votes 0 ·

1 Answer

surferonwww avatar image
0 Votes"
surferonwww answered surferonwww edited

If you receive HTTP 404.17 - Not Found can the following articles help?

What causes WCF Error 404.17 to be shown?
https://stackoverflow.com/questions/25532110/what-causes-wcf-error-404-17-to-be-shown

HTTP Error 404.17 - Not Found
https://stackoverflow.com/questions/7083533/http-error-404-17-not-found

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.