当我将Sql参数Arrey作为参数传递给Wcf服务时给出错误 [英] When I Am Passing Sql Parameter Arrey As Parameter To Wcf Service In Is Giving Error

查看:94
本文介绍了当我将Sql参数Arrey作为参数传递给Wcf服务时给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误



输入数据合约名称为'string:http:/的'System.Data.SqlTypes.SqlString' /www.w3.org/2001/XMLSchema'不是预期的。考虑使用DataContractResolver或将任何静态未知的类型添加到已知类型列表中 - 例如,使用KnownTypeAttribute属性或将它们添加到传递给DataContractSerializer的已知类型列表中。



客户代码

<前lang =cs> 受保护 void btnnextpersdetls_Click( object sender,EventArgs e)
{
SqlParameter [] _params = { new SqlParameter( @ UserName kotlanaveen23@gmail.com), new SqlParameter( @ password xswqaz)};
DataSet ds1 = new DataSet();
ds1 = objl.fnExecuteDataSet( hrrec T sp_GetEmpPersonalDetails ,_params);
}


服务方式

public DataSet fnExecuteDataSet( string schema, string connect_Test_or_Production, string p, params SqlParameter []参数)
{
// throw new NotImplementedException();
try
{
if (fnOpenConnection(schema,connect_Test_or_Production)== true
{
_objDataSet = new DataSet();
_objSqlDataAdapter = new SqlDataAdapter();
_objSQLCommand = new SqlCommand();

_objSQLCommand.Connection = _objSQLConnection;
_objSQLCommand.CommandType = CommandType.StoredProcedure;
_objSQLCommand.CommandText = p;

foreach (SqlParameter objParamaeter in 参数)
{
_objSQLCommand.Parameters.Add(objParamaeter);
}

_objSqlDataAdapter.SelectCommand = _objSQLCommand;
_objSqlDataAdapter.Fill(_objDataSet);

return _objDataSet;
}
其他
{
返回 ;
}
}
catch (SqlException dbEx)
{
return null ;
}
catch (例外情况)
{
return null ;
}
最后
{
_objDataSet = null ;
_objSqlDataAdapter = null ;
_objSQLCommand = null ;
fnCloseConnection();
}
}

解决方案

你应该重新设计您的WCF输入,以使用Fly Weight对象封装您要发送到服务调用的信息,而不是发送SqlParameter对象。这样,您也不仅仅与MS SQL特定的调用绑定。


Error

Type 'System.Data.SqlTypes.SqlString' with data contract name 'string:http://www.w3.org/2001/XMLSchema' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

client code

protected void btnnextpersdetls_Click(object sender, EventArgs e)
    {
SqlParameter[] _params = { new SqlParameter("@UserName","kotlanaveen23@gmail.com"),new SqlParameter("@password","xswqaz")};
DataSet ds1 = new DataSet();
ds1 = objl.fnExecuteDataSet("hrrec", "T", "sp_GetEmpPersonalDetails", _params);
}


service method

public DataSet fnExecuteDataSet(string schema, string connect_Test_or_Production, string p, params SqlParameter[] Parameters)
    {
        // throw new NotImplementedException();
        try
        {
            if (fnOpenConnection(schema, connect_Test_or_Production) == true)
            {
                _objDataSet = new DataSet();
                _objSqlDataAdapter = new SqlDataAdapter();
                _objSQLCommand = new SqlCommand();

                _objSQLCommand.Connection = _objSQLConnection;
                _objSQLCommand.CommandType = CommandType.StoredProcedure;
                _objSQLCommand.CommandText = p;

                foreach (SqlParameter objParamaeter in Parameters)
                {
                    _objSQLCommand.Parameters.Add(objParamaeter);
                }

                _objSqlDataAdapter.SelectCommand = _objSQLCommand;
                _objSqlDataAdapter.Fill(_objDataSet);

                return _objDataSet;
            }
            else
            {
                return null;
            }
        }
        catch (SqlException dbEx)
        {
            return null;
        }
        catch (Exception ex)
        {
            return null;
        }
        finally
        {
            _objDataSet = null;
            _objSqlDataAdapter = null;
            _objSQLCommand = null;
            fnCloseConnection();
        }
    }

解决方案

You should probably redesign your WCF inputs to use a Fly Weight object to encapsulate the information that you want to send to the service call and not send SqlParameter objects. This way you are also not just tied to MS SQL specific calls.


这篇关于当我将Sql参数Arrey作为参数传递给Wcf服务时给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆