我只是想尝试使用webServices,而且我遇到了一些问题。
ASP.NET Visual Studio 2013 SQL Server 2012 C#
我创建了一个webService,它接受一个ID号并返回一个数据列表。我使用DataSet重新编译数据。一切正常(我可以看到XML中的数据),但是没有显示在XML(GameDate和GameTime)中的第2列。 GameDate设置为日期,GameTime在SQL中设置为时间。
XML结果
<DataSet xmlns="http://tempuri.org/">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" minOccurs="0"/>
<xs:element name="FirstName" type="xs:string" minOccurs="0"/>
<xs:element name="TeamName" type="xs:string" minOccurs="0"/>
<xs:element name="GameDate" type="xs:dateTime" minOccurs="0"/>
<xs:element name="GameTime" type="xs:duration" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<ID>2301</ID>
<FirstName>Hamel</FirstName>
<TeamName>Team Bring It</TeamName>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<ID>3826</ID>
<FirstName>Coté</FirstName>
<TeamName>Team Bring It</TeamName>
</Table>
<Table diffgr:id="Table3" msdata:rowOrder="2">
<ID>5017</ID>
<FirstName>Barrette</FirstName>
<TeamName>Team Bring It</TeamName>
</Table>
<Table diffgr:id="Table4" msdata:rowOrder="3">
<ID>5549</ID>
<FirstName>Therrien</FirstName>
<TeamName>Team Bring It</TeamName>
</Table>
<Table diffgr:id="Table5" msdata:rowOrder="4">
<ID>6763</ID>
<FirstName>Perreault</FirstName>
<TeamName>Team Bring It</TeamName>
</Table>
<Table diffgr:id="Table6" msdata:rowOrder="5">
<ID>992</ID>
<FirstName>Poliquin</FirstName>
<TeamName>Renegades</TeamName>
</Table>
<Table diffgr:id="Table7" msdata:rowOrder="6">
<ID>1840</ID>
<FirstName>Bouthillier</FirstName>
<TeamName>Renegades</TeamName>
</Table>
<Table diffgr:id="Table8" msdata:rowOrder="7">
<ID>2747</ID>
<FirstName>Bouchard</FirstName>
<TeamName>Renegades</TeamName>
</Table>
<Table diffgr:id="Table9" msdata:rowOrder="8">
<ID>4096</ID>
<FirstName>Archambault</FirstName>
<TeamName>Renegades</TeamName>
</Table>
<Table diffgr:id="Table10" msdata:rowOrder="9">
<ID>5741</ID>
<FirstName>Vivace</FirstName>
<TeamName>Renegades</TeamName>
</Table>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
C#代码
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;
/// <summary>
/// Summary description for TestWS
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 TestWS : System.Web.Services.WebService
{
public TestWS()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public DataSet getListLigue(int numero)
{
string connString = ConfigurationManager.ConnectionStrings["DB_36624_hlm_ConnectionString"].ConnectionString;
using (DataSet dataset = new DataSet())
{
using (SqlConnection conn = new SqlConnection(connString))
{
using (SqlDataAdapter adapter = new SqlDataAdapter())
{
using (SqlCommand cmd = new SqlCommand("uspCeduleByPlayer", conn))
{
cmd.Parameters.Add(new SqlParameter("@p_ID", numero));
cmd.CommandType = CommandType.StoredProcedure;
adapter.SelectCommand = cmd;
adapter.Fill(dataset);
return dataset;
}
}
}
}
}
}