這些方法AutoComplete.asmxWeb服務的錯誤,我發現了錯誤的Web服務
[WebMethod]
public List<string> GetCountries(string prefixText)
{
SqlConnection con = new SqlConnection(
ConfigurationManager.ConnectionStrings[
"MarinaNewConnectionString"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand(
"select * from Marina where Country like @Name+'%'", con);
cmd.Parameters.AddWithValue("@Name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List<string> CountryNames = new List<string>();
for(int i=0;i<dt.Rows.Count;i++)
{
CountryNames.Add(dt.Rows[i][5].ToString());
}
return CountryNames;
}
我發現錯誤
System.InvalidOperationException:有一個錯誤生成XML文檔。 --->
System.InvalidCastException:無法轉換類型的對象
編輯:
該表的SQL:
CREATE TABLE [dbo].[Marina](
[SNo] [int] IDENTITY(1,1) NOT NULL,
[WebSource] [varchar](500) NULL,
[MarinaName] [varchar](500) NULL,
[Region] [varchar](500) NULL,
[Address] [varchar](500) NULL,
[Country] [varchar](500) NULL,
[fax] [varchar](500) NULL,
[Phone] [varchar](500) NULL,
[Email] [varchar](500) NULL,
[Website] [varchar](500) NULL,
[latitude] [varchar](500) NULL,
[langitude] [varchar](500) NULL,
[NumberOfMoorings] [varchar](500) NULL,
[MGiD] [varchar](500) NULL,
[Association] [varchar](200) NULL,
)) ON [PRIMARY]
棧跟蹤:
System.InvalidOperationException:生成時發生錯誤XML文檔。 ---> System.InvalidCastException:無法投射類型爲'System.Collections.Generic.List`1 [System.String]'的對象 以鍵入 'System.String []'。在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_Arr ayOfString(對象 O)在 Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfStringSerializer1.Serialize(對象 objectToSerialize,XmlSerializationWriter作家)
你可以發佈堆棧跟蹤嗎? – Rajesh 2012-02-02 10:53:44
這是我的表 CREATE TABLE [DBO]。[濱海]( \t [斯諾] [INT] IDENTITY(1,1)NOT NULL, \t [WebSource] [VARCHAR(500)NULL, \t [MarinaName ] [VARCHAR](500)NULL, \t [地區] [VARCHAR](500)NULL, \t [地址] [VARCHAR](500)NULL, \t [國家] [VARCHAR](500)NULL, \t [500] NULL, \t [Website] [var](500)NULL, \t [Phone] [varchar](500)NULL, \t [Email] [varchar]字符](500)NULL, \t [緯度] [VARCHAR](500)NULL, \t [langitude] [VARCHAR](500)NULL, \t [NumberOfMoorings] [VARCHAR](500)NULL, \t [MGID ] [varchar](500)NULL, \t [Association] [varchar](200)NULL, ) )ON [PRIMARY] – 2012-02-02 10:56:22
System.InvalidOperationException:生成XML文檔時發生錯誤。 ---> System.InvalidCastException:無法強制轉換'System.Collections.Generic.List'1 [System.String]'類型的對象以鍵入'System.String []'。 at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_ArrayOfString(Object o) at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfStringSerializer1.Serialize(Object objectToSerialize,XmlSerializationWriter writer) – 2012-02-02 10:58:48