从asmx webservice中提取struct数据

时间:2012-10-19 13:21:47

标签: c# asp.net sql web-services asmx

我有以下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隐式转换为字符串[]

0 个答案:

没有答案