在IIS上发布websevice

150 篇文章 0 订阅
3 篇文章 0 订阅

1.新建asp.net web应用程序,选择空项目

2.在项目中,右键,添加新项目,选择web服务

3 添加方法

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

namespace MyWebService
{
    /// <summary>
    /// WebServiceTest 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class WebServiceTest : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public int Add(int a,int b)
        {
            return a + b;
        }
    }
}

4 在web服务文件上右键,在浏览器中查看

 

5.点add进去

6.此时表明用localhost可以访问web服务

7 在web项目中(注意不是web服务文件),点击右键,发布

 

8 点击编辑

9 更改发布的目标位置,点击下一页,保存,回到上面的发布页面,点击发布

10 此时在发布的位置就会有下面的文件

11 在控制面版中,程序和功能界面,选择左边的启动或关闭Windows功能

12 选择Internet Information Services,一定要选择Web管理工具和万维网服务,注意将IIS 6管理兼容性都选上

13 万维网服务下面的应用程序开发功能,注意选择和webservice兼容的ASP.NET版本及扩展性都选上,最好整个开发功能都勾上,这里如果不勾的话,无法通过IIS访问webservice

14 在IIS中,在网站上右键添加网站,物理地址选择刚才发布的地址,IP地址选择本机IP即可

15.选择右侧浏览功能,既可以看到同本地访问webservice同样的界面

16 复制上面的网址

17重新打开vs新建一个控制台程序,添加服务引用

18 在地址栏粘贴上面的网址,选择转到,既可以找到web服务,确定引入

19 修改主程序既可以访问到webservice

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp7
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceReference1.WebServiceTestSoapClient client = new ServiceReference1.WebServiceTestSoapClient();
            int result = client.Add(2, 3);
            Console.WriteLine(result.ToString());
            Console.ReadLine();
        }
    }
}

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值