【发布时间】:2012-09-24 10:06:19
【问题描述】:
我正在尝试发布我的 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
}
}
【问题讨论】:
-
为什么将 web.config 设置为 none 以进行发布?
-
我将其设置为无,因为我找到了据说可能是解决方案的主题..
-
奇怪 - 我刚刚将 Namespace = "tempuri.org" 更改为 "yahoo.com" 并且.. VS 重建解决方案没有错误,然后我关闭 VS 打开它再次尝试重建。 ..再次出现同样的错误。顺便说一句,在成功重建后,我发布了服务但没有收到文件 .asmx 任何线索为什么?
标签: c# asp.net web-services asmx