blogSite

我是谁?我在哪儿?我在干什么?

View project on GitHub

C# 新建项目格式及说明

.asmx

  • .asmx 是WEB服务文件
  • .asmx.cs 里有相关代码
// MachineLearningWorkflow.asmx.cs
using CBPRService.Library;
using ConditionService;
using System;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace CBPRService.CBPR.MachineLearning
{
    /// <summary>
    /// MachineLearningWorkflow 的摘要说明
    /// </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 MachineLearningWorkflow : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            // 获取url中的参数
            string itemId = HttpContext.Current.Request.QueryString["itemId"];
            return "Hello World";
        }
    }
}
  1. [System.Web.Script.Services.ScriptService] 如果把这个注释注释掉就没办法从Ajax等脚本中调用这个接口

首页 > 学习总览 > 开发语言 > C#