web服务问题:用户代码未处理 System.ArgumentException 不支持关键字'source'
代码如下:newspublish.asmx.cs
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// NewsPublish 的摘要说明
/// </summary>
[WebService(Namespace = "http://localhost/news", Description = "该系统提供了10个服务。")]//此出namespace要写成该服务在IIS上网址,否则会出错“ 未能创建类型“NewsPublish”
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class NewsPublish : System.Web.Services.WebService
{
public string ConnectionString = "Source=ZXB;Initial Catalog=news;Integrated Security=True";
//SqlConnection conn = new SqlConnection(ConnectionString);
public NewsPublish ()
{
}
[WebMethod(Description = "该服务用于验证用户身份,返回值表示验证是否通过。")]
public bool VerifyUser(string username, string password)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConnectionString;
bool bRet = false;
SqlCommand cmd = new SqlCommand("VerifyUser", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.VarChar,50));
cmd.Parameters["@username"].Value = username;
cmd.Parameters.Add(new SqlParameter("@password", SqlDbType.VarChar, 50));
cmd.Parameters["@password"].Value = password;
cmd.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
cmd.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
try
{
conn.Open();
cmd.ExecuteNonQuery();
int ret = (int)cmd.Parameters["@return"].Value;
if (ret == 0)
{
bRet = true;
}
}
catch { }
finally
{ conn.Close(); }
return bRet;
}
在aspx。cs文件里调用,就出现了这个错误。
忘高手提点提点 --------------------编程问答-------------------- 补充一下:conn.ConnectionString = ConnectionString;是显示这句出错。 --------------------编程问答-------------------- public string ConnectionString = "Source=ZXB;......";
这里是Data Source=ZXB --------------------编程问答-------------------- public string ConnectionString = "Data Source=ZXB;Initial Catalog=news;Integrated Security=True "; --------------------编程问答-------------------- 改为server试试 --------------------编程问答-------------------- 检查连接字符窜。。。
补充:.NET技术 , ASP.NET