• XML Web Service开发实例——通过Windows Forms调用Web Service


     
    开发平台:.NET 2.0
    开发工具:Visual Web Developer 2005 Express Edition Beta Visual C# 2005 Express Edition Beta

    Service.asmx
    <%@ WebService Language="C#" CodeBehind="~/Code/Service.cs" Class="MyServiceCS" %>

    Service.cs
    using System;
    using System.Web;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web.Services;
    using System.Web.Services.Protocols;

    [WebServiceBinding(ConformanceClaims=WsiClaims.BP10,EmitConformanceClaims = true)]
    public class MyServiceCS : System.Web.Services.WebService
    {
    public MyServiceCS()
    {
    }

    [WebMethod]
    public int AddNumbers(int num1, int num2)
    {
    return (num1+num2);
    }

    [WebMethod]
    public int SubNumbers(int num1, int num2)
    {
    return (num1-num2);
    }

    [WebMethod]
    public int MulNumbers(int num1, int num2)
    {
    return (num1*num2);
    }

    [WebMethod]
    public int DivNumbers(int num1, int num2)
    {
    return (num1/num2);
    }
    }

    Form1.cs
    #region Using directives

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    #endregion

    namespace ArithCalculatorWebServiceClient
    {
    partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private MyServiceCS CSService = new MyServiceCS();

    private void LblResult_Click(object sender, EventArgs e)
    {
    int result = CSService.AddNumbers(Int32.Parse(TxtNum1.Text),Int32.Parse(TxtNum2.Text));
    LblResult.Text = result.ToString();
    }

    private void BtnSub_Click(object sender, EventArgs e)
    {
    int result = CSService.SubNumbers(Int32.Parse(TxtNum1.Text), Int32.Parse(TxtNum2.Text));
    LblResult.Text = result.ToString();
    }

    private void BtnMul_Click(object sender, EventArgs e)
    {
    int result = CSService.MulNumbers(Int32.Parse(TxtNum1.Text), Int32.Parse(TxtNum2.Text));
    LblResult.Text = result.ToString();
    }

    private void BtnDiv_Click(object sender, EventArgs e)
    {
    int result = CSService.DivNumbers(Int32.Parse(TxtNum1.Text), Int32.Parse(TxtNum2.Text));
    LblResult.Text = result.ToString();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    }
    }

  • 相关阅读:
    Android基本功:Socket
    Javascript模板及其中的数据逻辑分离思想
    MFC,QT与WinForm,WPF简介
    GPIB、USB、PCI、PCI Express和以太网/LAN/LXI
    Office批量授权(VL)版本和激活方法
    Labview 错误1400-打包库封装类时将对类重命名导致
    console.log()
    a标签中href=""的几种用法
    正斜杠"/"与反斜杠""
    提问的艺术
  • 原文地址:https://www.cnblogs.com/godwar/p/988043.html
Copyright © 2020-2023  润新知