重建ASMX Web服务时出错

时间:2012-09-24 10:06:19

标签: c# asp.net web-services asmx

我正在尝试发布我的Web服务,我已经将.asmx文件的Build Action属性更改为“Compile”,将Web.config更改为“None”但是当我尝试重建解决方案时仍然会出现以下错误:< / p>

Error   1   Keyword, identifier, or string expected after verbatim specifier: @ \MyVirtualCartWS\MyVirtualCartWS.asmx

Error   2   A namespace cannot directly contain members such as fields or methods   \MyVirtualCartWS\MyVirtualCartWS.asmx

两个错误都指向.asmx文件,所以这里是:

<%@ WebService Language="C#" CodeBehind="MyVirtualCartWS.asmx.cs" Class="MyVirtualCartWS.MyVirtualCartWS" %>

背后的代码

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


namespace MyVirtualCartWS
{
    /// <summary>
    /// Summary description MyVirtualCartWS
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [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 MyVirtualCartWS : System.Web.Services.WebService
    {

        #region Using LoggedUser

        [WebMethod]
        public LoggedUser AddUser(string _login, string _email, string _password)
        {
            LoggedUser lUser = new LoggedUser();
            lUser.AddUser(_login, _email, _password);
            return lUser;
        }

        [WebMethod]
        public LoggedUser LogIn(string _login, string _password)
        {
            LoggedUser lUser = new LoggedUser();
            lUser.LogIn(_login, _password);
            return lUser;
        }

        #endregion
    }
}

1 个答案:

答案 0 :(得分:0)

该行:

[System.Web.Script.Services.ScriptService]

应该先取消注释。