Why isn't my WCF/WPF service working?

Anonymous
2022-09-10T08:37:21.763+00:00

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();

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
698 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,415 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,681 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,288 questions
{count} votes

3 answers

Sort by: Most helpful
  1. SurferOnWww 1,916 Reputation points
    2022-09-12T00:37:00.877+00:00

    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

    0 comments No comments

  2. ElChefe 76 Reputation points
    2022-11-08T06:55:57.79+00:00

    package com.example.verbesserung;

    import com.example.verbesserung.Model.Absence;
    import com.example.verbesserung.Model.Pupil;

    import java.util.*;

    public class DataStore {

    private static DataStore instance;  
    private Set<Pupil> pupils = new HashSet<>();  
    
    private DataStore() {  
        UUID uuid = UUID.randomUUID();  
        pupils.add(new Pupil(uuid));  
        Absence absence = new Absence();  
        getPupilById(uuid).get().addAbsence(absence);  
        getPupilById(uuid).get().addAbsence(absence);  
        System.out.println("\n\n----------------------------------- Size = " + getPupilById(uuid).get().getAbsences().size() + "-----------------------------------------");  
    }  
    
    public static DataStore getInstance() {  
        if (instance == null) {  
            instance = new DataStore();  
        }  
        return instance;  
    }  
    
    public Set<Pupil> getPupils(){  
        return pupils;  
    }  
    
    public Optional<Pupil> getPupilById(UUID id) {  
        return pupils.stream()  
                .filter(pupil -> pupil.getId().equals(id))  
                .findFirst();  
    }  
    
    public void addPupil(Pupil p){  
        pupils.add(p);  
    }  
    

    }

    0 comments No comments

  3. ElChefe 76 Reputation points
    2022-11-08T06:56:45.673+00:00

    <%@ page import="javax.xml.crypto.Data" %>
    <%@ page import="com.example.verbesserung.DataStore" %>
    <%@ page import="com.example.verbesserung.Model.Pupil" %>
    <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <!DOCTYPE html>
    <html>
    <head>
    <title>JSP - Hello World</title>
    </head>
    <body>
    <h1><%= "Hello World!" %>
    </h1>
    <br/>
    <a href="anzeige-berechnung">Hello Servlet</a>

    <form action="anzeige-berechnung" method="post">

    <label for="pupils">Waehlen Sie einen Schueler:</label>  
    
    <select name="pupils" id="pupils">  
    <% for(Pupil p : DataStore.getInstance().getPupils()){ %>  
        <option value="<%=p.getId()%>"><%=p.getFirstName() + " " + p.getLastName()%></option>  
    <% } %>  
    </select>  
    
    <br>  
    <input type="submit" name="Abwesenheiten anzeigen">  
    

    </form>

    </body>
    </html>

    --------------------------

    package com.example.verbesserung.Servlets;

    import java.io.*;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Set;
    import java.util.UUID;

    import com.example.verbesserung.DataStore;
    import com.example.verbesserung.Model.Absence;
    import com.example.verbesserung.Model.Pupil;
    import jakarta.servlet.ServletException;
    import jakarta.servlet.http.;
    import jakarta.servlet.annotation.
    ;

    @WebServlet(name = "anzeige-berechnung", value = "/anzeige-berechnung")
    public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {  
        message = "Hello World!";  
    }  
    
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {  
        response.setContentType("text/html");  
    
        // Hello  
        PrintWriter out = response.getWriter();  
        out.println("<html><body>");  
        out.println("<h1>" + message + "</h1>");  
        out.println("</body></html>");  
    }  
    
    public void destroy() {  
    }  
    
    @Override  
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {  
        String id = req.getParameter("pupils");  
    
        Pupil pupil = DataStore.getInstance().getPupilById(UUID.fromString(id)).get();  
        ArrayList<Absence> absenceList = pupil.getAbsences();  
    
        req.setAttribute("pupilBean",absenceList);  
        req.getRequestDispatcher("anzeige.jsp").forward(req,resp);  
    
        /*  
        <select name="cars" id="cars">  
        <%=for(Pupil p : DataStore.getInstance().getPupils())%>  
        <option value="volvo">Volvo</option>  
        <option value="saab">Saab</option>  
        <option value="opel">Opel</option>  
        <option value="audi">Audi</option>  
    </select>  
    
         */  
    }  
    

    }

    --------------------------------------------

    <%@ page import="com.example.verbesserung.Model.Pupil" %>
    <%@ page import="java.util.ArrayList" %>
    <%@ page import="com.example.verbesserung.Model.Absence" %><%--
    Created by IntelliJ IDEA.
    User: Startklar
    Date: 22.05.2022
    Time: 12:09
    To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
    <title>Title</title>
    <jsp:useBean id="pupilBean" type="java.util.ArrayList<com.example.verbesserung.Model.Absence>" scope="request"></jsp:useBean>
    </head>
    <body>
    <table border="1">
    <tr>
    <th>ID</th>
    <th>From</th>
    <th>To</th>
    <th>Reason</th>
    <th>Excused?</th>
    </tr>

        <%  
            for(Absence absence : pupilBean){  
                out.println("<tr>");  
                out.println("<td>" + absence.getId() + "</td>");  
                out.println("<td>" + absence.getFrom() + "</td>");  
                out.println("<td>" + absence.getTo() + "</td>");  
                out.println("<td>" + absence.getReason() + "</td>");  
                out.println("<td>" + absence.getExcused() + "</td>");  
                out.println("</tr>");  
            }  
        %>  
    
    
    </table>  
    

    </body>
    </html>

    ----------------------

    package com.example.verbesserung.Interface;

    import com.example.verbesserung.Model.Absence;
    import jakarta.json.Json;
    import jakarta.ws.rs.*;
    import jakarta.ws.rs.core.MediaType;
    import jakarta.ws.rs.core.Response;

    import java.util.UUID;

    public interface IPupil {
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @mutia keyza ("{pupil_id}/absence")
    public Response neueAbwesenheit(@PathParam("pupil_id") UUID pupil_id, Absence absence);

    @GET  
    @Produces(MediaType.APPLICATION_JSON)  
    @Path("{pupil_id}/absence/{absence_id}")  
    public Response abwesenheitAbrufen(@PathParam("pupil_id") UUID pupil_id,  
                                       @PathParam("absence_id") UUID absence_id);  
    
    @PUT  
    @Path("{pupil_id}/absence/{absence_id}/excuse")  
    public Response entschuldigen(@PathParam("pupil_id") UUID pupil_id,  
                                  @PathParam("absence_id") UUID absence_id);  
    

    }

    0 comments No comments