初次使用Webservice,请各位大侠指教!!
随便写了一个
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Xml.Serialization;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] TEST_WEB_SERVICE()
{
string[] Result = new string[2];
Result[0] = "Hello";
Result[1] = "World";
return Result;
}
[WebMethod]
//[XmlInclude(typeof(List<string>))]
public List<string> Test_Hello_World()
{
List<string> Result = new List<string>();
Result.Add("Hello");
Result.Add("World");
return Result;
}
[WebMethod]
public DataTable TEST_GET_RESULT()
{
DataTable Result = new DataTable();
Result.Columns.Add("Hello", typeof(string));
Result.Columns.Add("World", typeof(string));
DataRow dr = Result.NewRow();
dr[0] = "Hello";
dr[1] = "World";
Result.Rows.Add(dr);
return Result;
}
}
调试该WebService时提示System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set.
at System.Data.DataTable.WriteXmlSchema(XmlWriter writer, Boolean writeHierarchy)
at System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter writer)
at System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)...........................
我看的一些书上的例子也是这样的,请问各位是什么原因???