我有以下 webservice 方法,当我在 localhost 的服务参考页面测试它时它工作正常,它返回带有数据的 Xml 文件。该方法返回两个数组的结构。我试图创建一个 C# 客户端,但我在提取数据时遇到了困难。这是我的代码。
public struct GetWeatherItemDataStruct
{
//public DateTime[] TimeStamp;
public double[] Value;
public string[] TimeStamp;
}
[WebMethod]
public GetWeatherItemDataStruct GetWeatherItemData(string parameterName,string fromTime,string toTime)
{
GetWeatherItemDataStruct gwiDataStructObj = new GetWeatherItemDataStruct();
SqlConnection conn = null;
SqlDataReader rdr = null;
int prameterID = GetParameterID(parameterName);
int tblSize = GetTableSize(parameterName, fromTime, toTime, prameterID);
double[] result = new double[tblSize];
int i = 0;
string[] tStamp = new string[tblSize];
String source = "Data Source=MASTER-PC\\SQLEXPRESS;Initial Catalog=WeatherDatabase;Integrated Security=True";
try
{
using (conn = new SqlConnection(source))// create and open a connection object
{
// 1. create a command object identifying
// the stored procedure
SqlCommand cmd = new SqlCommand("GetWeatherItemData", conn);
// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
// 3. add parameter to command, which
// will be passed to the stored procedure
//cmd.Parameters.Add(new SqlParameter("@WeatherParameterID", "1"));
cmd.Parameters.Add("@WeatherParameter", SqlDbType.VarChar).Value = parameterName;
cmd.Parameters.Add("@FromTimeStamp", SqlDbType.VarChar).Value = fromTime;
cmd.Parameters.Add("@ToTimeStamp", SqlDbType.VarChar).Value = toTime;
conn.Open();
// execute the command
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
result[i] = (double)rdr["MeasurementValue"];
tStamp[i] = rdr["Recieved"].ToString();
i++;
}
gwiDataStructObj.Value = result;
gwiDataStructObj.TimeStamp = tStamp;
}
}
catch (SqlException e)
{
//Log exception
//Display Error message
}
return gwiDataStructObj;
}
我如何从这种方法中读取?。我不太确定如何创建客户端,到目前为止我写的是这样的:
var client = new WebServiceSample.WebService1SoapClient();
string paramName = "Windsensor";
string dtFrom="2012-10-04 19:05:57:190";
string dtTo="2012-10-05 21:50:05:197";
int paramID = 0;
double[] paramValue;
double[] paramValue;
double[] tStamp;
double i;
paramValue = client.GetWeatherItemData(paramName, dtFrom, dtTo).Value;
tStamp =client.GetWeatherItemData(paramName, dtFrom, dtTo).TimeStamp;
我的问题是这两行:
paramValue = client.GetWeatherItemData(paramName, dtFrom, dtTo).Value;
tStamp =client.GetWeatherItemData(paramName, dtFrom, dtTo).TimeStamp;
我收到错误消息:无法将 SoapWebServiceClient.WebServiceSample.ArrayOfDouble 隐式转换为 double[]
并且不能将 SoapWebServiceClient.WebServiceSample.ArrayOfString 隐式转换为 string[]