Web Service Demo

有了Web Service的一些基础,具体如何实现,通过亲自写一个Demo来理解一下。

1.创建一个空的Web项目

 2.在Web项目下ADD一个Web Service

3.在Web service中写个简答的方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Demo
{
    /// <summary>
    /// WebService Demo
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]//WebService别名
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Myservice : System.Web.Services.WebService
    {
        [WebMethod]//特性
        public int add(int a, int b)
        {
            return a * b;
        }
    }
}
Myservice.asmx

4.项目完成,开始发布。

 4.1 Publish method选择File System 

    

猜你喜欢

转载自www.cnblogs.com/cdjbolg/p/11792924.html