Recherche…


Introduction

Un exemple ASP.Net très simple du strict minimum de code pour créer un WebService.

Remarques

Dans un article séparé de la documentation StackOverflow, nous examinerons comment utiliser ce service Web Calculator.

Calculatrice WebService

<%@ WebService Language="C#" Class="Util" %>
using System;
using System.Web.Services;

public class Util: WebService
{
    [WebMethod]
    public int CalculatorAdd(int operandA, int operandB)
    {
        return operandA + operandB;
    }

    [WebMethod]
    public int CalculatorSubtract(int operandA, int operandB)
    {
        return operandA - operandB;
    }

    [WebMethod]
    public long CalculatorMultiply(int operandA, int operandB)
    {
        return operandA * operandB;
    }
    
    [WebMethod]
    public long CalculatorDivide(int operandNumerator, int operandDenominator)
    {
        if (operandDenominator == 0)
            return System.Int64.MaxValue;    // Should really do better error handling overall & return an error
        else
            return operandNumerator / operandDenominator;
    }
}


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow