zoukankan      html  css  js  c++  java
  • C# Web Service简单使用

    第一步 打开VS,新建一个项目

     

    第二步  创建一个ASP.NET 空 Web应用程序

    我这里用的是VS2017

    第三步 添加一个Web 服务(ASMX)

    右键解决方案-->添加-->新建项

    找到Web 服务(ASMX)

    第四步 编写WebService的代码部分

    创建完成后可以看到下面的画面

    默认有个Hello Word的方法,我们将这个方法删除,写上两个两数求和差的方法(注:方法上需要加上WebMethod的特性)

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 using System.Web.Services;
     6 
     7 namespace FirstWebService
     8 {
     9     /// <summary>
    10     /// WebService 的摘要说明
    11     /// </summary>
    12     [WebService(Namespace = "http://tempuri.org/")]
    13     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    14     [System.ComponentModel.ToolboxItem(false)]
    15     // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    16     // [System.Web.Script.Services.ScriptService]
    17     public class WebService : System.Web.Services.WebService
    18     {
    19 
    20         [WebMethod]
    21         public double Sum(double num1,double num2)
    22         {
    23             return num1 + num2;
    24         }
    25 
    26         [WebMethod]
    27         public double Sub(double num1, double num2)
    28         {
    29             return num1 - num2;
    30         }
    31     }
    32 }
  • 相关阅读:
    HDU1026 Ignatius and the Princess I
    luogu_1865 A % B Problem
    luogu_1092 虫食算
    luogu_1111 修复公路
    luogu_1265 公路修建
    luogu_2330 [SCOI2005]繁忙的都市
    luogu_1613 跑路
    luogu_3386 【模板】二分图匹配
    luogu_3388 【模板】割点(割顶)
    luogu_2327 扫雷
  • 原文地址:https://www.cnblogs.com/LYF1997/p/7880553.html
Copyright © 2011-2022 走看看