急死人啦,怎么webservice调用存储过程老是出不来结果?在线等
存储过程:
CREATE PROCEDURE dbo.CheckVessel
(
@CS_Code varchar(20),
@Vessel_Code varchar(20),
@Station_ID char(3),
@Message varchar(50) OUTPUT
)
as
BEGIN
……
if
begin
……
set @Message= '修改成功 '
end
else
begin
set @Message= '不能修改 '
end
END
GO
webservice 调用的时候:
public string CheckVessel(string cs_code,string vessel_code,string station_id)
{
string rtnValue=string.Empty;
using (SqlConnection con=new SqlConnection(this.connString))
{
SqlCommand cmd=con.CreateCommand();
cmd.CommandText= "CheckVessel ";
cmd.CommandType=CommandType.StoredProcedure;
con.Open();
cmd.Parameters.Add( "@CS_Code ",SqlDbType.VarChar).Value=cs_code;
cmd.Parameters.Add( "@Vessel_Code ",SqlDbType.VarChar).Value=vessel_code;
cmd.Parameters.Add( "@Station_ID ",SqlDbType.Char).Value=station_id;
cmd.Parameters.Add( "@Message ",SqlDbType.VarChar).Value= " ";
cmd.Parameters[ "@Message "].Direction=ParameterDirection.Output;
try
{
int i=cmd.ExecuteNonQuery();
rtnValue=cmd.Parameters[ "@Message "].Value.ToString();
Console.WriteLine(rtnValue);
}
catch(Exception eX)
{
Console.WriteLine(eX.ToString());
LogError.Write(eX.ToString());
}
}
return rtnValue;
}
但是rtnValue的值总是空
[解决办法]
换一个调用方法 CheckVessel替换为call checkvessel{?,?,?,?}
[解决办法]
仅供参考:
parameters[3].Value = 0;
parameters[3].Direction = ParameterDirection.Output;
parameters[4].Value = 0;
parameters[4].Direction = ParameterDirection.Output;
DataTable table = DataTool.ExecuteDataTable( "usp_GetList ", CommandType.StoredProcedure, parameters);
rowcount = Convert.ToInt32(parameters[3].Value);
pagecount = Convert.ToInt32(parameters[4].Value);
[解决办法]
在webconfig中加入 <webServices> <protocols> <add name= "HttpPost "/> <add name= "HttpGet "/> </protocols> </webServices>