• 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)
    {

    }
    }
    }

  • 相关阅读:
    优雅的将hbase的数据导入hive表
    大数据技术-spark+hive+hbase研究
    第0001课
    线程池-实际生产使用
    H5学习系列之文件读取API--本文转自http://blog.csdn.net/jackfrued/article/details/8967667
    H5学习系列之Communication API
    H5学习系列之Geolocation API
    H5学习系列之Audio和Video
    H5学习系列之webSocket入门
    百度UEditor基本使用
  • 原文地址:https://www.cnblogs.com/godwar/p/988043.html
Copyright © 2020-2023  润新知