zoukankan      html  css  js  c++  java
  • 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)
    {

    }
    }
    }

  • 相关阅读:
    1.初识Redis
    2.API的理解和使用
    8.rabbitmq RPC模拟微服务架构中的服务调用
    9.[完]其他常用的rabbitmq的参数和设置
    6.Header交换机之模拟验证用户身份
    C#中复制文件夹及文件的两种方法
    python通过递归将多维字典转化为二维
    python venv flask gunicorn 部署与 pycharm 连接
    Nagios(centos 6.5)调用NSClient++/NRPE+Powershell脚本(windows server 2008 r2)监控网络情况
    Nagios 调用华为云短信平台进行报警
  • 原文地址:https://www.cnblogs.com/godwar/p/988043.html
Copyright © 2011-2022 走看看