我正在尝试发布我的 Web 服务,我已经将 .asmx 文件的构建操作属性更改为“编译”,并将 Web.config 更改为“无”,但是当我尝试重建解决方案时仍然出现以下错误:
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
}
}